This is a client library for NATS written in rust.
Special thanks for supporting development of this project.
This package can be installed from pypi:
pip install natsrpy
Or alternatively you can build it yourself using maturin, and stable rust.
import asyncio from natsrpy import Nats async def main() -> None: nats = Nats(["nats://localhost:4222"]) await nats.startup() subscription = await nats.subscribe("hello") await nats.publish("hello", "str world") subscription.unsubscribe(limit=1) async for message in subscription: print(message) # Don't forget to call shutdown. await nats.shutdown() if __name__ == "__main__": asyncio.run(main())
You can see more usage examples in our examples folder.
Also, our tests are written in python and could be a good place to discover features and the way they intended to be used.
As of for now, our documentation is only availabe in source code. You can see it in our type-stubs folder.
We use stable rust and pyo3 for writing python extension module. In order to build the project, use uv and maturin.
uv is used for all python-side dependencies (including dev deps). Maturin is used only for building rust-side.
# To create .venv folder uv venv # Sync deps uv sync --locked # To build and install the package in a virtual environment uv run -- maturin dev --uv
If you want to setup automatic rebuilds, use this command:
uv run -- python -m maturin_import_hook site install
It will force rebuild project when rust code changes.
For lints please use pre-commit.
pre-commit run -a