linkr 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of linkr might be problematic. Click here for more details.
- linkr-0.1.0/.gitignore +12 -0
- linkr-0.1.0/LICENSE +21 -0
- linkr-0.1.0/PKG-INFO +150 -0
- linkr-0.1.0/README.md +127 -0
- linkr-0.1.0/pyproject.toml +78 -0
- linkr-0.1.0/src/linkr/__init__.py +38 -0
- linkr-0.1.0/src/linkr/app.py +456 -0
- linkr-0.1.0/src/linkr/di.py +82 -0
- linkr-0.1.0/src/linkr/exceptions.py +25 -0
- linkr-0.1.0/src/linkr/middleware/__init__.py +2 -0
- linkr-0.1.0/src/linkr/middleware/base.py +57 -0
- linkr-0.1.0/src/linkr/middleware/gzip.py +41 -0
- linkr-0.1.0/src/linkr/models.py +91 -0
- linkr-0.1.0/src/linkr/py.typed +0 -0
- linkr-0.1.0/src/linkr/serializer.py +41 -0
- linkr-0.1.0/src/linkr/transports/__init__.py +85 -0
- linkr-0.1.0/src/linkr/transports/mock.py +87 -0
- linkr-0.1.0/src/linkr/transports/rmq.py +320 -0
linkr-0.1.0/.gitignore
ADDED
linkr-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
linkr-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: linkr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Async RPC framework with middleware support
|
|
5
|
+
Project-URL: Homepage, https://github.com/levsh/linkr
|
|
6
|
+
Project-URL: Repository, https://github.com/levsh/linkr
|
|
7
|
+
Project-URL: BugTracker, https://github.com/levsh/linkr/issues
|
|
8
|
+
Author-email: Roman Koshel <roma.koshel@gmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: amqp,async,framework,middleware,rabbitmq,rpc
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
20
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
21
|
+
Requires-Python: <4,>=3.11
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# linkr
|
|
25
|
+
|
|
26
|
+
Async RPC framework.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
pip install linkr
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quickstart
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from linkr import MockTransport, RpcApp
|
|
38
|
+
|
|
39
|
+
transport = MockTransport()
|
|
40
|
+
app = RpcApp(transport)
|
|
41
|
+
|
|
42
|
+
@app.method("add")
|
|
43
|
+
def add(x: int, y: int) -> int:
|
|
44
|
+
return x + y
|
|
45
|
+
|
|
46
|
+
await app.init()
|
|
47
|
+
await app.consume()
|
|
48
|
+
|
|
49
|
+
result = await app.make("add", 2, 3).call()
|
|
50
|
+
print(result) # 5
|
|
51
|
+
|
|
52
|
+
await app.close()
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
- Decorator-based handler registration
|
|
58
|
+
- Timeout, TTL, RTTL per call
|
|
59
|
+
- Fire-and-forget via publish()
|
|
60
|
+
- App-level middleware (`AppMiddleware`)
|
|
61
|
+
- Wire-level middleware (`WireMiddleware`) — compression, encryption
|
|
62
|
+
- Gzip compression via `GzipMiddleware`
|
|
63
|
+
- Dependency injection with `Depends[T]`
|
|
64
|
+
- Pydantic serialization
|
|
65
|
+
- Mock transport for testing (no broker needed)
|
|
66
|
+
- RabbitMQ transport
|
|
67
|
+
|
|
68
|
+
## App-level Middleware
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import logging
|
|
72
|
+
|
|
73
|
+
from linkr import AppMiddleware
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class LoggingMiddleware(AppMiddleware):
|
|
77
|
+
async def dispatch(self, ctx, call_next):
|
|
78
|
+
if ctx.direction == "request" and ctx.role == "server":
|
|
79
|
+
logging.info("[%s] Calling", ctx.request.id)
|
|
80
|
+
result = await call_next(ctx)
|
|
81
|
+
if ctx.direction == "response" and ctx.role == "server" and ctx.response:
|
|
82
|
+
logging.info("[%s] Done", ctx.request.id)
|
|
83
|
+
return result
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
app.add_middleware(LoggingMiddleware())
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Wire-level Middleware
|
|
90
|
+
|
|
91
|
+
Compression, encryption and other wire transformations use `WireMiddleware`:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from linkr import GzipMiddleware
|
|
95
|
+
|
|
96
|
+
app.add_middleware(GzipMiddleware())
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Custom wire-level middleware inherits from `WireMiddleware` and works with `ctx.body`:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
import gzip
|
|
103
|
+
from linkr import WireMiddleware
|
|
104
|
+
from linkr.models import RpcContext
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class CustomCompression(WireMiddleware):
|
|
108
|
+
async def dispatch(self, ctx: RpcContext, call_next):
|
|
109
|
+
if ctx.direction == "request" and ctx.role == "client":
|
|
110
|
+
ctx.body = gzip.compress(ctx.body)
|
|
111
|
+
elif ctx.direction == "request" and ctx.role == "server":
|
|
112
|
+
ctx.body = gzip.decompress(ctx.body)
|
|
113
|
+
|
|
114
|
+
ctx = await call_next(ctx)
|
|
115
|
+
|
|
116
|
+
if ctx.direction == "response" and ctx.role == "server":
|
|
117
|
+
ctx.body = gzip.compress(ctx.body)
|
|
118
|
+
elif ctx.direction == "response" and ctx.role == "client":
|
|
119
|
+
ctx.body = gzip.decompress(ctx.body)
|
|
120
|
+
|
|
121
|
+
return ctx
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Dependency Injection
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from linkr import Depends
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class Database:
|
|
131
|
+
...
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
app.dependencies.add_singleton(Database, lambda: Database("postgres://..."))
|
|
135
|
+
|
|
136
|
+
@app.method("ping")
|
|
137
|
+
def ping(db: Depends[Database]) -> str:
|
|
138
|
+
return db.url
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Transports
|
|
142
|
+
|
|
143
|
+
| Transport | When to use |
|
|
144
|
+
|---------------|----------------------------|
|
|
145
|
+
| MockTransport | Unit tests, local dev |
|
|
146
|
+
| RmqTransport | Production (RabbitMQ) |
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
MIT
|
linkr-0.1.0/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# linkr
|
|
2
|
+
|
|
3
|
+
Async RPC framework.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pip install linkr
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from linkr import MockTransport, RpcApp
|
|
15
|
+
|
|
16
|
+
transport = MockTransport()
|
|
17
|
+
app = RpcApp(transport)
|
|
18
|
+
|
|
19
|
+
@app.method("add")
|
|
20
|
+
def add(x: int, y: int) -> int:
|
|
21
|
+
return x + y
|
|
22
|
+
|
|
23
|
+
await app.init()
|
|
24
|
+
await app.consume()
|
|
25
|
+
|
|
26
|
+
result = await app.make("add", 2, 3).call()
|
|
27
|
+
print(result) # 5
|
|
28
|
+
|
|
29
|
+
await app.close()
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- Decorator-based handler registration
|
|
35
|
+
- Timeout, TTL, RTTL per call
|
|
36
|
+
- Fire-and-forget via publish()
|
|
37
|
+
- App-level middleware (`AppMiddleware`)
|
|
38
|
+
- Wire-level middleware (`WireMiddleware`) — compression, encryption
|
|
39
|
+
- Gzip compression via `GzipMiddleware`
|
|
40
|
+
- Dependency injection with `Depends[T]`
|
|
41
|
+
- Pydantic serialization
|
|
42
|
+
- Mock transport for testing (no broker needed)
|
|
43
|
+
- RabbitMQ transport
|
|
44
|
+
|
|
45
|
+
## App-level Middleware
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import logging
|
|
49
|
+
|
|
50
|
+
from linkr import AppMiddleware
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class LoggingMiddleware(AppMiddleware):
|
|
54
|
+
async def dispatch(self, ctx, call_next):
|
|
55
|
+
if ctx.direction == "request" and ctx.role == "server":
|
|
56
|
+
logging.info("[%s] Calling", ctx.request.id)
|
|
57
|
+
result = await call_next(ctx)
|
|
58
|
+
if ctx.direction == "response" and ctx.role == "server" and ctx.response:
|
|
59
|
+
logging.info("[%s] Done", ctx.request.id)
|
|
60
|
+
return result
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
app.add_middleware(LoggingMiddleware())
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Wire-level Middleware
|
|
67
|
+
|
|
68
|
+
Compression, encryption and other wire transformations use `WireMiddleware`:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from linkr import GzipMiddleware
|
|
72
|
+
|
|
73
|
+
app.add_middleware(GzipMiddleware())
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Custom wire-level middleware inherits from `WireMiddleware` and works with `ctx.body`:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import gzip
|
|
80
|
+
from linkr import WireMiddleware
|
|
81
|
+
from linkr.models import RpcContext
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class CustomCompression(WireMiddleware):
|
|
85
|
+
async def dispatch(self, ctx: RpcContext, call_next):
|
|
86
|
+
if ctx.direction == "request" and ctx.role == "client":
|
|
87
|
+
ctx.body = gzip.compress(ctx.body)
|
|
88
|
+
elif ctx.direction == "request" and ctx.role == "server":
|
|
89
|
+
ctx.body = gzip.decompress(ctx.body)
|
|
90
|
+
|
|
91
|
+
ctx = await call_next(ctx)
|
|
92
|
+
|
|
93
|
+
if ctx.direction == "response" and ctx.role == "server":
|
|
94
|
+
ctx.body = gzip.compress(ctx.body)
|
|
95
|
+
elif ctx.direction == "response" and ctx.role == "client":
|
|
96
|
+
ctx.body = gzip.decompress(ctx.body)
|
|
97
|
+
|
|
98
|
+
return ctx
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Dependency Injection
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from linkr import Depends
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class Database:
|
|
108
|
+
...
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
app.dependencies.add_singleton(Database, lambda: Database("postgres://..."))
|
|
112
|
+
|
|
113
|
+
@app.method("ping")
|
|
114
|
+
def ping(db: Depends[Database]) -> str:
|
|
115
|
+
return db.url
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Transports
|
|
119
|
+
|
|
120
|
+
| Transport | When to use |
|
|
121
|
+
|---------------|----------------------------|
|
|
122
|
+
| MockTransport | Unit tests, local dev |
|
|
123
|
+
| RmqTransport | Production (RabbitMQ) |
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
MIT
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "linkr"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Async RPC framework with middleware support"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11,<4"
|
|
7
|
+
license = { text = "MIT" }
|
|
8
|
+
keywords = ["rpc", "async", "framework", "rabbitmq", "amqp", "middleware"]
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Roman Koshel", email = "roma.koshel@gmail.com" },
|
|
11
|
+
]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
21
|
+
"Topic :: System :: Distributed Computing",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/levsh/linkr"
|
|
26
|
+
Repository = "https://github.com/levsh/linkr"
|
|
27
|
+
BugTracker = "https://github.com/levsh/linkr/issues"
|
|
28
|
+
|
|
29
|
+
[tool.poetry.dependencies]
|
|
30
|
+
python = ">=3.11,<4.0"
|
|
31
|
+
pydantic = ">=2.0"
|
|
32
|
+
rmqaio = ">=0.18.0"
|
|
33
|
+
|
|
34
|
+
[tool.poetry.group.test.dependencies]
|
|
35
|
+
docker = "*"
|
|
36
|
+
mypy = "*"
|
|
37
|
+
pytest = "*"
|
|
38
|
+
pytest-asyncio = "*"
|
|
39
|
+
pytest-cov = "*"
|
|
40
|
+
|
|
41
|
+
[build-system]
|
|
42
|
+
requires = ["hatchling"]
|
|
43
|
+
build-backend = "hatchling.build"
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.wheel]
|
|
46
|
+
packages = ["src/linkr"]
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.sdist]
|
|
49
|
+
include = [
|
|
50
|
+
"/src",
|
|
51
|
+
"/LICENSE",
|
|
52
|
+
"/README.md",
|
|
53
|
+
"/pyproject.toml",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[tool.ruff]
|
|
57
|
+
line-length = 88
|
|
58
|
+
|
|
59
|
+
[tool.ruff.lint]
|
|
60
|
+
select = ["E", "F", "I", "N", "W", "UP"]
|
|
61
|
+
|
|
62
|
+
[tool.mypy]
|
|
63
|
+
python_version = "3.11"
|
|
64
|
+
ignore_missing_imports = true
|
|
65
|
+
disallow_any_generics = true
|
|
66
|
+
disallow_subclassing_any = true
|
|
67
|
+
check_untyped_defs = true
|
|
68
|
+
disallow_untyped_defs = true
|
|
69
|
+
disallow_untyped_decorators = true
|
|
70
|
+
no_implicit_optional = true
|
|
71
|
+
warn_redundant_casts = true
|
|
72
|
+
|
|
73
|
+
[tool.pytest.ini_options]
|
|
74
|
+
testpaths = ["tests"]
|
|
75
|
+
asyncio_mode = "auto"
|
|
76
|
+
markers = [
|
|
77
|
+
"integration: tests that require external services like Docker",
|
|
78
|
+
]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import importlib.metadata
|
|
2
|
+
|
|
3
|
+
from linkr.app import HandlerInfo, RpcApp, RpcCall
|
|
4
|
+
from linkr.di import Depends, DiContainer
|
|
5
|
+
from linkr.exceptions import RpcError
|
|
6
|
+
from linkr.middleware.base import AppMiddleware, BaseMiddleware, WireMiddleware
|
|
7
|
+
from linkr.middleware.gzip import GzipMiddleware
|
|
8
|
+
from linkr.models import RpcContext, RpcData, RpcHeaders, RpcRequest, RpcResponse
|
|
9
|
+
from linkr.serializer import JsonSerializer, Serializer
|
|
10
|
+
from linkr.transports import Transport
|
|
11
|
+
from linkr.transports.mock import MockTransport
|
|
12
|
+
from linkr.transports.rmq import RmqTransport
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"Depends",
|
|
16
|
+
"DiContainer",
|
|
17
|
+
"RpcCall",
|
|
18
|
+
"HandlerInfo",
|
|
19
|
+
"RpcApp",
|
|
20
|
+
"RpcError",
|
|
21
|
+
"AppMiddleware",
|
|
22
|
+
"BaseMiddleware",
|
|
23
|
+
"WireMiddleware",
|
|
24
|
+
"GzipMiddleware",
|
|
25
|
+
"RpcRequest",
|
|
26
|
+
"RpcResponse",
|
|
27
|
+
"RpcContext",
|
|
28
|
+
"RpcData",
|
|
29
|
+
"RpcHeaders",
|
|
30
|
+
"JsonSerializer",
|
|
31
|
+
"Serializer",
|
|
32
|
+
"Transport",
|
|
33
|
+
"MockTransport",
|
|
34
|
+
"RmqTransport",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
__version__ = importlib.metadata.version("rmqaio")
|