Skip to content

Commit

Permalink
Merge pull request #2 from zerlok/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
zerlok authored Nov 21, 2024
2 parents 898b0b1 + 5947eb7 commit 410a319
Show file tree
Hide file tree
Showing 29 changed files with 1,631 additions and 289 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Danil Troshnev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,37 @@ message brokers.
## key features

* same protobuf structures as in gRPC
* same unary / stream calls as in gRPC
* similar calls as in gRPC
* unary-unary
* (TODO) unary-stream
* (TODO) stream-unary
* (TODO) stream-stream
* declarative style, abstract from broker commands (such as declare_exchange / queue_bind)
* publisher & consumer middlewares
* message serializers

### codegen
## codegen

(TODO) provide codegen integration with [pyprotostuben](https://github.com/zerlok/pyprotostuben)
You can generate python code for server & client from `.proto` files.
The [pyprotostuben](https://github.com/zerlok/pyprotostuben) project provides protoc plugin `protoc-gen-brokrpc`. See
pyprotostuben project example for more details.

## supported brokers & protocols

* [AMQP](https://www.rabbitmq.com/tutorials/amqp-concepts)
* [aiormq](https://github.com/mosquito/aiormq)
* (TODO) redis
* (TODO) kafka
* (TODO) NATS

## usage

install with pip or poetry
[pypi package](https://pypi.python.org/pypi/BrokRPC)

```shell
pip install BrokRPC
```
install with your favorite python package manager

```shell
poetry add BrokRPC
pip install BrokRPC[aiormq]
```

### Broker
Expand Down
852 changes: 679 additions & 173 deletions poetry.lock

Large diffs are not rendered by default.

50 changes: 38 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,62 @@
[tool.poetry]
name = "BrokRPC"
version = "0.1.0"
description = ""
description = "framework for gRPC like server-client communication over message brokers"
authors = ["zerlok <[email protected]>"]
readme = "README.md"
license = "MIT"
keywords = [
"python",
"protobuf",
"amqp",
"grpc",
"message-queue",
"message-broker",
]
classifiers = [
"Development Status :: 1 - Planning",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Application Frameworks",
"Topic :: System :: Networking",
"Typing :: Typed",
]

[tool.poetry.dependencies]
python = "^3.12"
protobuf = "^5.26.1"
aiormq = {version = "^6.8.1"}
googleapis-common-protos = "^1.65.0"
yarl = "^1.18.0"
protobuf = {version = "^5.26.1", optional = true}
googleapis-common-protos = {version = "^1.65.0", optional = true}
aiormq = {version = "^6.8.1", optional = true}
aiofiles = {version = "^24.1.0", optional = true}

[tool.poetry.extras]
cli = ["aiofiles"]
protobuf = ["protobuf", "googleapis-common-protos"]
aiormq = ["aiormq"]

[tool.poetry.scripts]
brokrpc = "brokrpc.cli:main"

[tool.poetry.group.dev.dependencies]
types-protobuf = "^5.26.0.20240422"
mypy = "^1.10.0"
pytest = "^8.2.0"
mypy = "^1.13.0"
pytest = "^8.3.3"
pytest-cov = "^5.0.0"
ruff = "^0.4.9"
ruff = "^0.7.4"
pytest-asyncio = "^0.24.0"
pyprotostuben = "^0.1.2"
pytest-timeout = "^2.3.1"

pytest-mypy-plugins = "^3.1.2"
types-aiofiles = "^24.1.0.20240626"
pyprotostuben = "0.2.1"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
target-version = "py312"
include = ["src/**/*.py", "tests/**/*.py"]
exclude = ["**_pb2.py", "**_pb2.pyi", "**_pb2_grpc.py", "**_pb2_grpc.pyi"]
line-length = 120
Expand Down Expand Up @@ -62,9 +91,6 @@ strict = true
module = ["google.rpc.*"]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = ["brokrpc.rpc.protobuf.*", "tests.integration.rpc.*"]
ignore_errors = true

[tool.pytest.ini_options]
pythonpath = [
Expand Down
3 changes: 1 addition & 2 deletions src/brokrpc/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class BrokerIsNotConnectedError(BrokerError):


class Broker(t.AsyncContextManager["Broker"]):
# NOTE: broker is a high level API class, constructor provides configuring it with different options
def __init__( # noqa: PLR0913
def __init__(
self,
options: BrokerConnectOptions,
*,
Expand Down
6 changes: 3 additions & 3 deletions src/brokrpc/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def build(
@t.overload
def build(
self,
inner: t.Callable[[U], t.Awaitable[V]],
inner: t.Callable[[U], t.Coroutine[object, object, V]],
options: BindingOptions,
) -> t.AsyncContextManager[BoundConsumer]: ...

Expand All @@ -196,7 +196,7 @@ def build(

def build(
self,
inner: Consumer[U, V] | t.Callable[[U], t.Awaitable[V]] | t.Callable[[U], V],
inner: Consumer[U, V] | t.Callable[[U], t.Coroutine[object, object, V]] | t.Callable[[U], V],
options: BindingOptions,
executor: Executor | None = None,
) -> t.AsyncContextManager[BoundConsumer]:
Expand All @@ -209,7 +209,7 @@ def build(
case async_func if inspect.iscoroutinefunction(async_func):
consumer = AsyncFuncConsumer(async_func)

case sync_func if inspect.isfunction(sync_func):
case sync_func if callable(sync_func):
consumer = SyncFuncConsumer(t.cast(t.Callable[[U], V], sync_func), executor)

case _:
Expand Down
Loading

0 comments on commit 410a319

Please sign in to comment.