Catalog PyPI
Back to packageRELEASE DETAILS

4.1.2

PyPI

aiocent

Async Python library to communicate with Centrifugo v3 HTTP API, fork of pycent package

Published29 Feb 2024
Direct dependencies1
Transitive dependenciesNot calculated

README

Version 4.1.2 documentation

AIOCENT

async fork of pycent

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

To install run:

pip install aiocent

High-level library API

First see available API methods in documentation.

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

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.:

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:

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:

[{}]

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
  2. Changelog, push and create new tag
  3. pip install twine
  4. pip install wheel
  5. python setup.py sdist bdist_wheel
  6. twine check dist/*
  7. twine upload dist/*

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 1

Native requirements
1 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
aiohttp
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": "",
  "evaluation": "NOT_EVALUATED"
}
aiohttpruntime

Distribution files

2 collected
aiocent-4.1.2-py3-none-any.whl

bdist_wheel · 7.21 KB · Python py3

Source file
aiocent-4.1.2.tar.gz

sdist · 4.79 KB · Python source

Source file

Repository

PENDING
valid_var/aiocent

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 11:43 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:32e7168cc711a59b80d89460dedaa3d82bfa91bdb835f18eb7bb4f864a00f77a

Other collected versions

View all collected versions →