natsio


Namenatsio JSON
Version 0.2.1 PyPI version JSON
download
home_pageNone
SummaryNATS client for Python
upload_time2024-04-04 22:45:03
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords asyncio client nats nats-client nats-python nats.io
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # natsio – Modern Python client for NATS

---

## Basic usage

```python
import asyncio

from natsio.client import NATSCore, ClientConfig
from natsio.messages import CoreMsg


async def callback(msg: CoreMsg) -> None:
    text = f"Received message from {msg.subject}: {msg.payload}"
    if msg.headers:
        text += f" with headers: {msg.headers}"
    print(text)
    if msg.reply_to:
        await msg.reply(b"OK")


async def main() -> None:
    config = ClientConfig(servers=["nats://localhost:4222"])

    async with NATSCore(config) as client:
        sub = await client.subscribe("foo.>", callback=callback)
        await sub.unsubscribe(max_msgs=3) # Automatically unsubscribe after 3 messages

        await client.publish("foo.bar", b"Hello, World!", reply_to="foo.bar.reply")
        await client.publish("foo.baz", b"Hello, World!", headers={"x": "y"})

        await asyncio.Future()


def run() -> None:
    asyncio.run(main())


if __name__ == "__main__":
    run()
```

---

## Installation

```bash
pip install natsio
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "natsio",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Corrupt Mane <corruptmane@gmail.com>",
    "keywords": "asyncio, client, nats, nats-client, nats-python, nats.io",
    "author": null,
    "author_email": "Corrupt Mane <corruptmane@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/53/84/e2ad881c2016b63d575694071dcc8fffd6465e9c8426d0354acf95324d62/natsio-0.2.1.tar.gz",
    "platform": null,
    "description": "# natsio \u2013 Modern Python client for NATS\n\n---\n\n## Basic usage\n\n```python\nimport asyncio\n\nfrom natsio.client import NATSCore, ClientConfig\nfrom natsio.messages import CoreMsg\n\n\nasync def callback(msg: CoreMsg) -> None:\n    text = f\"Received message from {msg.subject}: {msg.payload}\"\n    if msg.headers:\n        text += f\" with headers: {msg.headers}\"\n    print(text)\n    if msg.reply_to:\n        await msg.reply(b\"OK\")\n\n\nasync def main() -> None:\n    config = ClientConfig(servers=[\"nats://localhost:4222\"])\n\n    async with NATSCore(config) as client:\n        sub = await client.subscribe(\"foo.>\", callback=callback)\n        await sub.unsubscribe(max_msgs=3) # Automatically unsubscribe after 3 messages\n\n        await client.publish(\"foo.bar\", b\"Hello, World!\", reply_to=\"foo.bar.reply\")\n        await client.publish(\"foo.baz\", b\"Hello, World!\", headers={\"x\": \"y\"})\n\n        await asyncio.Future()\n\n\ndef run() -> None:\n    asyncio.run(main())\n\n\nif __name__ == \"__main__\":\n    run()\n```\n\n---\n\n## Installation\n\n```bash\npip install natsio\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "NATS client for Python",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/corruptmane/natsio",
        "Repository": "https://github.com/corruptmane/natsio"
    },
    "split_keywords": [
        "asyncio",
        " client",
        " nats",
        " nats-client",
        " nats-python",
        " nats.io"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "50bd0058dfb9fded888907b9e8b09650f629593f4bff28314ef3d06662222e6d",
                "md5": "60693e051f1d33ffbaab98cbb5284c57",
                "sha256": "97547d83bb8d839af6dbb4d9c7adce2c68b9a95cbb50f8d1bf4522d371f81c91"
            },
            "downloads": -1,
            "filename": "natsio-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "60693e051f1d33ffbaab98cbb5284c57",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 32142,
            "upload_time": "2024-04-04T22:45:05",
            "upload_time_iso_8601": "2024-04-04T22:45:05.090081Z",
            "url": "https://files.pythonhosted.org/packages/50/bd/0058dfb9fded888907b9e8b09650f629593f4bff28314ef3d06662222e6d/natsio-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5384e2ad881c2016b63d575694071dcc8fffd6465e9c8426d0354acf95324d62",
                "md5": "6febd0fc93f2cbcd017468ccd8c85c2c",
                "sha256": "d3f40383b4f981cae89a62e44d16e5ade26b5dac8148e1b04f9cded2298890c6"
            },
            "downloads": -1,
            "filename": "natsio-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "6febd0fc93f2cbcd017468ccd8c85c2c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 25774,
            "upload_time": "2024-04-04T22:45:03",
            "upload_time_iso_8601": "2024-04-04T22:45:03.831795Z",
            "url": "https://files.pythonhosted.org/packages/53/84/e2ad881c2016b63d575694071dcc8fffd6465e9c8426d0354acf95324d62/natsio-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-04 22:45:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "corruptmane",
    "github_project": "natsio",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "natsio"
}
        
Elapsed time: 3.24078s