Skip to content

Commit d63cfae

Browse files
Add docstrings; prepare release 0.1.2 (#10)
1 parent f1b6d52 commit d63cfae

11 files changed

Lines changed: 474 additions & 147 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Protobunny
22

33
> [!WARNING]
4-
> The project is in early development.
4+
> The project is in early development.
5+
> The core functionality for the available backends is implemented and tested,
6+
> but the public API may undergo breaking changes before the 1.0 release.
57
68

79
Protobunny is the open-source evolution of [AM-Flow](https://am-flow.com)'s internal messaging library.
@@ -95,6 +97,7 @@ Documentation home page: [https://am-flow.github.io/protobunny/](https://am-flow
9597
- [x] **Result workflow**: Subscribe to results topics and receive protobunny `Result` messages produced by your callbacks.
9698
- [x] **Cloud-Native**: NATS (Core & JetStream) integration.
9799
- [ ] **Cloud Providers**: AWS (SQS/SNS) and GCP Pub/Sub.
100+
- [ ] **OpenTelemetry** Integration (Planned)
98101
- [ ] **More backends**: Kafka support.
99102
- [ ] **gRPC** Direct Call support
100103

docs/source/api.rst

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
API Reference
22
=============
33

4-
Core Package
5-
------------
4+
Core Package Async
5+
------------------
66

7-
.. automodule:: protobunny
8-
:members:
97
.. automodule:: protobunny.asyncio
108
:members:
9+
10+
Core Package Sync
11+
-----------------
12+
13+
.. automodule:: protobunny
14+
:members:
1115
:no-index:
1216

1317
Models
@@ -48,6 +52,17 @@ Redis aio backend
4852
:members:
4953
:no-index:
5054

55+
56+
NATS aio backend
57+
-----------------
58+
.. automodule:: protobunny.asyncio.backends.nats
59+
:members:
60+
.. automodule:: protobunny.asyncio.backends.nats.connection
61+
:members:
62+
.. automodule:: protobunny.asyncio.backends.nats.queues
63+
:members:
64+
:no-index:
65+
5166
Python aio backend
5267
------------------
5368
.. automodule:: protobunny.asyncio.backends.python
@@ -91,6 +106,17 @@ Redis backend
91106
:members:
92107
:no-index:
93108

109+
NATS backend
110+
----------------
111+
.. automodule:: protobunny.backends.nats
112+
:members:
113+
.. automodule:: protobunny.backends.nats.connection
114+
:members:
115+
.. automodule:: protobunny.backends.nats.queues
116+
:members:
117+
:no-index:
118+
119+
94120
Python backend
95121
----------------
96122
.. automodule:: protobunny.backends.python
@@ -113,4 +139,3 @@ protobunny utility
113139
------------------
114140
.. automodule:: protobunny.wrapper
115141
:members:
116-
:undoc-members:

docs/source/quick_start.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ For a full example, using FastAPI, Redis, and protobunny, see [this repo](https:
99
## Setup
1010

1111
### pyproject.toml
12-
Add `protobunny` to your `pyproject.toml` dependencies:
12+
Add `protobunny` to your `pyproject.toml` dependencies (add the backend you need as extra dependency):
1313

1414
```shell
1515
uv add protobunny[rabbitmq, numpy]
@@ -325,7 +325,7 @@ messages-directory = "messages"
325325
messages-prefix = "acme"
326326
generated-package-name = "mymessagelib"
327327
generated-package-root = "codegen"
328-
backend = "rabbitmq"
328+
backend = "rabbitmq" # configure here the backend (choose between rabbitmq, redis, mosquitto, nats, python)
329329
mode = "async"
330330
```
331331

@@ -376,22 +376,19 @@ You should find the generated classes under `codegen/mymessagelib`.
376376
### Python code to test the library
377377

378378
```python
379-
380379
import asyncio
381380
import logging
382-
import sys
381+
import time
383382

384383
import protobunny as pb
385384
from protobunny import asyncio as pb_asyncio
386-
387-
# sys.path.append(pb.default_configuration.generated_package_root)
388-
# this is needed when the python classes for your lib are generated in a subfolder
389-
# that is not in the namespace and it must not be treated as a package
390-
# It's just a sys.path.append("./codegen")
391-
pb.config_lib()
385+
# # sys.path.append(pb.default_configuration.generated_package_root)
386+
# sys.path.append("./codegen")
387+
pb.config_lib() # this is needed when the python classes for your lib are generated in a subfolder
392388

393389
import mymessagelib as ml
394390

391+
395392
logging.basicConfig(
396393
level=logging.INFO, format="[%(asctime)s %(levelname)s] %(name)s - %(message)s"
397394
)
@@ -411,20 +408,24 @@ class TestLibAsync:
411408

412409
async def worker1(self, task: ml.main.tasks.TaskMessage) -> None:
413410
log.info("1- Working on: %s", task)
411+
await asyncio.sleep(0.1)
414412

415413
async def worker2(self, task: ml.main.tasks.TaskMessage) -> None:
416414
log.info("2- Working on: %s", task)
415+
await asyncio.sleep(0.1)
417416

418417
async def on_message_mymessage(self, message: ml.main.MyMessage) -> None:
419418
log.info("Got main message: %s", message)
420419

420+
421421
def run_forever(self):
422422
asyncio.run(self.main())
423423

424424
def log_callback(self, incoming, body) -> None:
425425
log.info(f"LOG {incoming.routing_key}: {body}")
426426

427427
async def main(self):
428+
428429
await pb_asyncio.subscribe_logger(self.log_callback)
429430
await pb_asyncio.subscribe(ml.main.tasks.TaskMessage, self.worker1)
430431
await pb_asyncio.subscribe(ml.main.tasks.TaskMessage, self.worker2)
@@ -454,9 +455,11 @@ class TestLib:
454455

455456
def worker1(self, task: ml.main.tasks.TaskMessage) -> None:
456457
log.info("1- Working on: %s", task)
458+
time.sleep(0.1)
457459

458460
def worker2(self, task: ml.main.tasks.TaskMessage) -> None:
459461
log.info("2- Working on: %s", task)
462+
time.sleep(0.1)
460463

461464
def log_callback(self, incoming, body) -> None:
462465
log.info(f"LOG {incoming.routing_key}: {body}")
@@ -478,7 +481,8 @@ class TestLib:
478481

479482

480483
if __name__ == "__main__":
481-
if conf.use_async:
484+
config = pb.config
485+
if config.use_async:
482486
log.info("Using async")
483487
testlib = TestLibAsync()
484488
pb_asyncio.run_forever(testlib.main)

0 commit comments

Comments
 (0)