https://github.com/gr1n/nats-python
Python client for NATS messaging system
https://github.com/gr1n/nats-python
nats nats-client natsio python python-client
Last synced: 6 months ago
JSON representation
Python client for NATS messaging system
- Host: GitHub
- URL: https://github.com/gr1n/nats-python
- Owner: Gr1N
- License: mit
- Created: 2018-08-30T19:09:02.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-05-02T11:44:14.000Z (over 2 years ago)
- Last Synced: 2023-11-20T16:22:38.350Z (almost 2 years ago)
- Topics: nats, nats-client, natsio, python, python-client
- Language: Python
- Homepage: https://pypi.org/project/nats-python/
- Size: 62.5 KB
- Stars: 85
- Watchers: 6
- Forks: 21
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# nats-python
[](https://github.com/Gr1N/nats-python/actions?query=workflow%3Adefault) [](https://codecov.io/gh/Gr1N/nats-python)  
Python client for NATS messaging system.
This project is a replacement for abandoned [pynats](https://github.com/mcuadros/pynats). `nats-python` supports only Python 3.6+ and fully covered with typings.
Go to the [asyncio-nats](https://github.com/nats-io/asyncio-nats) project, if you're looking for `asyncio` implementation.
## Installation
```sh
$ pip install nats-python
```## Usage
```python
from pynats import NATSClientwith NATSClient() as client:
# Connect
client.connect()# Subscribe
def callback(msg):
print(f"Received a message with subject {msg.subject}: {msg}")client.subscribe(subject="test-subject", callback=callback)
# Publish a message
client.publish(subject="test-subject", payload=b"test-payload")# wait for 1 message
client.wait(count=1)
```## Contributing
To work on the `nats-python` codebase, you'll want to clone the project locally and install the required dependencies via [poetry](https://poetry.eustace.io):
```sh
$ git clone git@github.com:Gr1N/nats-python.git
$ make install
```To run tests and linters use command below:
```sh
$ make lint && make test
```If you want to run only tests or linters you can explicitly specify which test environment you want to run, e.g.:
```sh
$ make lint-black
```## License
`nats-python` is licensed under the MIT license. See the license file for details.