aiocent


Nameaiocent JSON
Version 4.1.2 PyPI version JSON
download
home_pagehttps://github.com/valid_var/aiocent
SummaryAsync Python library to communicate with Centrifugo v3 HTTP API, fork of pycent package
upload_time2024-02-29 23:33:31
maintainer
docs_urlNone
authorStepan Starovoitov
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # AIOCENT
## async fork of pycent

Async Python tools to communicate with Centrifugo HTTP API. Python >= 3.3 supported.

To install run:

```bash
pip install aiocent
```

### High-level library API

First see [available API methods in documentation](https://centrifugal.dev/docs/server/server_api#http-api).

This library contains `Client` class to send messages to Centrifugo from your python-powered backend:

```python
from aiocent import Client
import asyncio

url = "http://localhost:8000/api"
api_key = "XXX"

# initialize client instance.
client = Client(url, api_key=api_key, timeout=1)

# publish data into channel
channel = "public:chat"
data = {"input": "test"}
asyncio.run(client.publish(channel, data))

# other available methods
asyncio.run(client.unsubscribe("user_id", "channel"))
asyncio.run(client.disconnect("user_id"))
history = asyncio.run(client.history("public:chat"))
presence = asyncio.run(client.presence("public:chat"))
channels = asyncio.run(client.channels())
info = asyncio.run(client.info())
asyncio.run(client.history_remove("public:chat"))
```

`publish`, `disconnect`, `unsubscribe`, `history_remove` return `None` in case of success. Each of this commands can raise an instance of `CentException`.

I.e.:

```python
from aiocent import Client, CentException
import asyncio

client = Client("http://localhost:8000/api", api_key="XXX", timeout=1)
try:
    asyncio.run(client.publish("public:chat", {"input": "test"}))
except CentException:
    # handle exception
```

Depending on problem occurred exceptions can be:

* RequestException – HTTP request to Centrifugo failed
* ResponseError - Centrifugo returned some error on request

Both exceptions inherited from `CentException`.

### Low-level library API:

To send lots of commands in one request:

```python
from aiocent import Client, CentException
import asyncio

client = Client("http://localhost:8000/api", api_key="XXX", timeout=1)

params = {
    "channel": "python",
    "data": "hello world"
}

asyncio.run(client.add("publish", params))

try:
    result = asyncio.run(client.send())
except CentException:
    # handle exception
else:
    print(result)
```

You can use `add` method to add several messages which will be sent.

You'll get something like this in response:

```bash
[{}]
```

I.e. list of single response to each command sent. So you need to inspect response on errors (if any) yourself.

### Client initialization arguments

Required:

* address - Centrifugo HTTP API endpoint address

Optional:

* `api_key` - HTTP API key of Centrifugo 
* `timeout` (default: `1`) - timeout for HTTP requests to Centrifugo
* `json_encoder` (default: `None`) - set custom JSON encoder
* `send_func` (default: `None`) - set custom send function
* `verify` (default: `True`) - when set to `False` no certificate check will be done during requests.

## For maintainer

To release:

1. Bump version in `setup.py`
1. Changelog, push and create new tag
1. `pip install twine`
1. `pip install wheel`
1. `python setup.py sdist bdist_wheel`
1. `twine check dist/*`
1. `twine upload dist/*`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/valid_var/aiocent",
    "name": "aiocent",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Stepan Starovoitov",
    "author_email": "stepan.startech@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/82/09/f9e34af1c02f14f30025235c53dacc18c79f3dc9eb63f7f19df532a2c77e/aiocent-4.1.2.tar.gz",
    "platform": null,
    "description": "# AIOCENT\n## async fork of pycent\n\nAsync Python tools to communicate with Centrifugo HTTP API. Python >= 3.3 supported.\n\nTo install run:\n\n```bash\npip install aiocent\n```\n\n### High-level library API\n\nFirst see [available API methods in documentation](https://centrifugal.dev/docs/server/server_api#http-api).\n\nThis library contains `Client` class to send messages to Centrifugo from your python-powered backend:\n\n```python\nfrom aiocent import Client\nimport asyncio\n\nurl = \"http://localhost:8000/api\"\napi_key = \"XXX\"\n\n# initialize client instance.\nclient = Client(url, api_key=api_key, timeout=1)\n\n# publish data into channel\nchannel = \"public:chat\"\ndata = {\"input\": \"test\"}\nasyncio.run(client.publish(channel, data))\n\n# other available methods\nasyncio.run(client.unsubscribe(\"user_id\", \"channel\"))\nasyncio.run(client.disconnect(\"user_id\"))\nhistory = asyncio.run(client.history(\"public:chat\"))\npresence = asyncio.run(client.presence(\"public:chat\"))\nchannels = asyncio.run(client.channels())\ninfo = asyncio.run(client.info())\nasyncio.run(client.history_remove(\"public:chat\"))\n```\n\n`publish`, `disconnect`, `unsubscribe`, `history_remove` return `None` in case of success. Each of this commands can raise an instance of `CentException`.\n\nI.e.:\n\n```python\nfrom aiocent import Client, CentException\nimport asyncio\n\nclient = Client(\"http://localhost:8000/api\", api_key=\"XXX\", timeout=1)\ntry:\n    asyncio.run(client.publish(\"public:chat\", {\"input\": \"test\"}))\nexcept CentException:\n    # handle exception\n```\n\nDepending on problem occurred exceptions can be:\n\n* RequestException \u2013 HTTP request to Centrifugo failed\n* ResponseError - Centrifugo returned some error on request\n\nBoth exceptions inherited from `CentException`.\n\n### Low-level library API:\n\nTo send lots of commands in one request:\n\n```python\nfrom aiocent import Client, CentException\nimport asyncio\n\nclient = Client(\"http://localhost:8000/api\", api_key=\"XXX\", timeout=1)\n\nparams = {\n    \"channel\": \"python\",\n    \"data\": \"hello world\"\n}\n\nasyncio.run(client.add(\"publish\", params))\n\ntry:\n    result = asyncio.run(client.send())\nexcept CentException:\n    # handle exception\nelse:\n    print(result)\n```\n\nYou can use `add` method to add several messages which will be sent.\n\nYou'll get something like this in response:\n\n```bash\n[{}]\n```\n\nI.e. list of single response to each command sent. So you need to inspect response on errors (if any) yourself.\n\n### Client initialization arguments\n\nRequired:\n\n* address - Centrifugo HTTP API endpoint address\n\nOptional:\n\n* `api_key` - HTTP API key of Centrifugo \n* `timeout` (default: `1`) - timeout for HTTP requests to Centrifugo\n* `json_encoder` (default: `None`) - set custom JSON encoder\n* `send_func` (default: `None`) - set custom send function\n* `verify` (default: `True`) - when set to `False` no certificate check will be done during requests.\n\n## For maintainer\n\nTo release:\n\n1. Bump version in `setup.py`\n1. Changelog, push and create new tag\n1. `pip install twine`\n1. `pip install wheel`\n1. `python setup.py sdist bdist_wheel`\n1. `twine check dist/*`\n1. `twine upload dist/*`\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Async Python library to communicate with Centrifugo v3 HTTP API, fork of pycent package",
    "version": "4.1.2",
    "project_urls": {
        "Download": "https://github.com/valid_var/aiocent",
        "Homepage": "https://github.com/valid_var/aiocent"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bd4b76aaa544b569d2a9056fbb9562d0568667b2e5bce3ae665f832c04a3c69c",
                "md5": "424c1bd2a1ae61ecb729ec6d97efdc8c",
                "sha256": "85e0d0d90dd3b62bfa9bbcb201f27db8fe95be3ca3d143a7eb93d45b6a644048"
            },
            "downloads": -1,
            "filename": "aiocent-4.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "424c1bd2a1ae61ecb729ec6d97efdc8c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7384,
            "upload_time": "2024-02-29T23:33:29",
            "upload_time_iso_8601": "2024-02-29T23:33:29.621023Z",
            "url": "https://files.pythonhosted.org/packages/bd/4b/76aaa544b569d2a9056fbb9562d0568667b2e5bce3ae665f832c04a3c69c/aiocent-4.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8209f9e34af1c02f14f30025235c53dacc18c79f3dc9eb63f7f19df532a2c77e",
                "md5": "ceff8faaa4bb73418d21f23a00728dae",
                "sha256": "8c641750e035ddd381ed7f9fa218293fbb1e1ae8cf155b02ef8e571538e3b174"
            },
            "downloads": -1,
            "filename": "aiocent-4.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "ceff8faaa4bb73418d21f23a00728dae",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4901,
            "upload_time": "2024-02-29T23:33:31",
            "upload_time_iso_8601": "2024-02-29T23:33:31.972314Z",
            "url": "https://files.pythonhosted.org/packages/82/09/f9e34af1c02f14f30025235c53dacc18c79f3dc9eb63f7f19df532a2c77e/aiocent-4.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-29 23:33:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "valid_var",
    "github_project": "aiocent",
    "github_not_found": true,
    "lcname": "aiocent"
}
        
Elapsed time: 0.17131s