centrifugal / pycent Goto Github PK
View Code? Open in Web Editor NEWPython library to communicate with Centrifugo HTTP API. Synchronous and asynchronous clients included
License: MIT License
Python library to communicate with Centrifugo HTTP API. Synchronous and asynchronous clients included
License: MIT License
Hi,
from cent import Client, CentException
url = "https://localhost:8999"
api_key = "xxxxx"
client = Client(url, api_key=api_key, timeout=1)
client.channels()
when I ran the above code, got the below error
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I am trying to make a python client that reads the history and gets the latest message in realtime, but only so far have I only been able to do it with the time module. Is there a way I can get the updates in realtime like javascript?
I'm deploying centrifugo in a Django project and I need to manage a process if there are no more clients connected to centrifugo. It doesn't seem to me that cent supports this. Is there a way to find out (from python) how many clients are connected to centrifugo?
Or if you have some other recommendation, let me know. Thanks!
Hey, I've just spent few hours trying to figure out why centrifugo throws out "no sign found in API request". Would be nice to create a branch with 2.1.0 version to avoid confusion for new users.
Hello,
I hope this message finds you well. I am writing this issue today to kindly request you to consider making the cent package available through Anaconda.
There are several compelling reasons for this request:
Ease of Installation: Anaconda provides a simple, one-command installation process for packages. This simplicity would lower the entry barrier for new or less experienced users who might otherwise find it challenging to install and manage the cent package.
Environment Management: Anaconda allows users to create isolated environments. By making cent available in Anaconda, users would be able to use your package without worrying about version conflicts with other packages in their environment.
Reach More Users: Anaconda is widely used in the scientific community, especially among data scientists. Making cent available through Anaconda would allow your package to reach a wider audience and receive more exposure.
I believe that taking the step to make cent available in Anaconda would greatly increase its usability and accessibility.
Thank you for considering this request, and for the fantastic work you've done on the cent package.
Best,
Daniel Amaro
Hi sir, I want to using cent in backend to broadcast a event/message to Centrifugo. And I want to using feature async consumers
with it so I need to use idempotency_key
to prevent duplicated event when retry. But I read the code that the broadcast method does not have idempotency_key
parameter, right ?
How i can publish message to any user(s) by user id?
hi, currently client.send() fails if you try to publish data that contains datetime or Decimal objects in https://github.com/centrifugal/cent/blob/master/cent/core.py#L62
It would be great if one could specify a custom JSONEncoder to use somehow (for example the DjangoJSONEncoder if you happen to use django). What I'm trying to do is to publish my serialized django model object into a channel. Or do you think it's a bad idea?
btw thanks for the great work on centrifuge!
This is supported by Centrifugo for a long time and results in more performant API request handling (about 30% faster when no need to parse Form). Also I think it's better to utilize requests lib instead of urllib as requests already standard de facto for Python.
Hi!
Is there any real documentation for this library?
For instance:
generate_api_sign
Thanks!
__init__() missing 1 required positional argument: 'secret'
. It seems secret is needed when passing parameters for Client
. I added this and i get an wrong status code: 404
when i try to test publish
centrifugo is in docker-compose, using centrifugo/centrifugo:v3.0.1
config.json is:
{
"token_hmac_secret_key": "CENTRIFUGO_SECRET",
"api_key": "CENTRIFUGO_API_KEY",
"admin_password": "Qwerty123",
"admin_secret": "Qwerty123",
"port": 9000,
"namespaces": [
{
"name": "seed",
"history_size": 16,
"history_ttl": "512s",
"recover": true
}
],
"allowed_origins": ["*"]
}
docker-compose.yml is:
centrifugo:
container_name: centrifugo
image: centrifugo/centrifugo:v3.0.1
command: centrifugo -c config.json
volumes:
- ./external/centrifugo:/centrifugo
repr is:
self = <cent.core.Client object at 0x7f4f54c947c0>, url = 'http://centrifugo:9000', data = b'{"method": "publish", "params": {"channel": "seed:notifications", "data": {}, "skip_history": false}}'
error is:
cent.core.RequestException: wrong status code: 404
I am planning to use centrifugo as a service for a new channel layer, adding onto django channels. I would like to know if this project still receives updates so that I can rely on it.
Thanks a lot!
When attempting to use cent --config centrc superuser project_list
with Python 3.3 I receive the error:
POST data should be bytes or an iterable of bytes. It cannot be of type str.
The offending line is the urlopen on line 87 of core.py. Python 3.3 urlencode wants bytes.
Thanks again for your awesome work on centrifuge/cent!
Hi,
I am trying to generate a token for the client side user. I went through the documentation on generating token and signatures, and there is a note saying:
Note that our API clients already have functions to generate client token - you don't have to implement this yourself until you want to implement it for another language for which we don't have API client yet
I am using the latest version of centrifugo (v2.1.0) and cent (v3.0.0), but there is no such functions to generate the token. I have looked on the other cent versions (v2.1.0), and the generate_token
function and many other functions are available.
Am I missing something on the latest cent version? Could you please help me how to generate token for the client side so that I can connect to the centrifugo server? If it helps, I am using Pythton v3.6.7 and Django v2.1.7.
Thank you
To skip certificate check in some cases while in development
At moment we use wrong JSON key history
- it must be publications
Hello! Minor issue:
https://github.com/centrifugal/cent/blob/9c1fee78df02730fdb5f44e946a2383cfab2a672/cent/core.py#L264
Both fields are mapped to "publications", the second one should be offset
Thank you for your work!
I want to copy and modify your module to make it asynchronous, but I can not legally do this until you include license in your repository
Hello!
I am using Centrifugo in my Django project as a tool for publishing notifications.
All services (also Centrifugo) are in Docker containers on the same server.
I use Nginx as a proxy server for Centrifugo.
Centrifugo is available on endpoint https://my-domain.io/centrifugo
I try to publish a notification with publish method, but get an error:
from cent import Client, CentException
url = "https://my_domain.io/centrifugo"
api_key = "my_api_key"
client = Client(url, api_key=api_key, timeout=1)
channel = 'channel'
try:
client.publish('channel', {"value": "My message"})
except CentException as e:
print(e)
HTTPSConnectionPool(host='my-domain.io', port=443): Max retries exceeded with url: /centrifugo/api (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f088e765130>, 'Connection to my-domain.io timed out. (connect timeout=1)'))
Also I try to publish with python requests package and get almost the same error:
import json
import requests
command = {
"method": "publish",
"params": {
"channel": "channel",
"data": {
"value": "My message!"
}
}
}
api_key = "my-api-key"
data = json.dumps(command)
headers = {'Content-type': 'application/json', 'Authorization': 'apikey ' + api_key}
resp = requests.post("https://my-domain.io/centrifugo/api", data=data, headers=headers)
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
conn = connection.create_connection(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/connection.py", line 84, in create_connection
raise err
File "/usr/local/lib/python3.8/site-packages/urllib3/util/connection.py", line 74, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 976, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 308, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 171, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f088e765970>: Failed to establish a new connection: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 724, in urlopen
retries = retries.increment(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/retry.py", line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='my-domain.io', port=443): Max retries exceeded with url: /centrifugo/api (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f088e765970>: Failed to establish a new connection: [Errno 110] Connection timed out'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 119, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='my-domain.io', port=443): Max retries exceeded with url: /centrifugo/api (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f088e765970>: Failed to establish a new connection: [Errno 110] Connection timed out'))
But when I run the same commands from my local server, everything works as expected.
What am I doing wrong? Should I use a separate server (droplet) for Centrifugo?
Thank you in advance!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.