cent
Advanced tools
| Metadata-Version: 1.1 | ||
| Name: cent | ||
| Version: 3.0.1 | ||
| Summary: Python library to communicate with Centrifugo API | ||
| Version: 4.0.0 | ||
| Summary: Python library to communicate with Centrifugo v3 HTTP API | ||
| Home-page: https://github.com/centrifugal/cent | ||
@@ -10,8 +10,6 @@ Author: Alexandr Emelin | ||
| Download-URL: https://github.com/centrifugal/cent | ||
| Description: Python library to communicate with Centrifugo API | ||
| Description: Python library to communicate with Centrifugo v3 HTTP API | ||
| Platform: UNKNOWN | ||
| Classifier: Development Status :: 5 - Production/Stable | ||
| Classifier: Programming Language :: Python | ||
| Classifier: Programming Language :: Python :: 2.6 | ||
| Classifier: Programming Language :: Python :: 2.7 | ||
| Classifier: Programming Language :: Python :: 3.3 | ||
@@ -22,2 +20,4 @@ Classifier: Programming Language :: Python :: 3.4 | ||
| Classifier: Programming Language :: Python :: 3.7 | ||
| Classifier: Programming Language :: Python :: 3.8 | ||
| Classifier: Programming Language :: Python :: 3.9 | ||
| Classifier: Environment :: Console | ||
@@ -24,0 +24,0 @@ Classifier: Intended Audience :: Developers |
+97
-68
| # coding: utf-8 | ||
| try: | ||
| import urllib.parse as urlparse | ||
| except ImportError: | ||
| import urlparse | ||
| import urllib.parse as urlparse | ||
| import sys | ||
@@ -12,12 +8,6 @@ import json | ||
| PY2 = sys.version_info[0] == 2 | ||
| def to_bytes(s): | ||
| return s.encode("latin-1") | ||
| if not PY2: | ||
| def to_bytes(s): | ||
| return s.encode("latin-1") | ||
| else: | ||
| def to_bytes(s): | ||
| return s | ||
| class CentException(Exception): | ||
@@ -80,19 +70,2 @@ """ | ||
| def prepare_url(self): | ||
| """ | ||
| http(s)://centrifuge.example.com/api/ | ||
| Some work here to prepare valid API url: make it work even if following urls provided | ||
| during client initialization: | ||
| http(s)://centrifuge.example.com | ||
| http(s)://centrifuge.example.com/ | ||
| http(s)://centrifuge.example.com/api | ||
| http(s)://centrifuge.example.com/api/ | ||
| """ | ||
| address = self.address.rstrip("/") | ||
| api_path = "/api" | ||
| if not address.endswith(api_path): | ||
| address += api_path | ||
| return address | ||
| def add(self, method, params): | ||
@@ -110,5 +83,5 @@ data = { | ||
| self._messages = [] | ||
| url = self.prepare_url() | ||
| data = to_bytes("\n".join([json.dumps(x, cls=self.json_encoder) for x in messages])) | ||
| response = self._send(url, data) | ||
| data = to_bytes( | ||
| "\n".join([json.dumps(x, cls=self.json_encoder) for x in messages])) | ||
| response = self._send(self.address, data) | ||
| return [json.loads(x) for x in response.split("\n") if x] | ||
@@ -126,3 +99,4 @@ | ||
| try: | ||
| resp = self.session.post(url, data=data, headers=headers, timeout=self.timeout, verify=self.verify) | ||
| resp = self.session.post( | ||
| url, data=data, headers=headers, timeout=self.timeout, verify=self.verify) | ||
| except requests.RequestException as err: | ||
@@ -138,33 +112,47 @@ raise RequestException(err) | ||
| @staticmethod | ||
| def get_publish_params(channel, data, uid=None): | ||
| def get_publish_params(channel, data, skip_history=False): | ||
| params = { | ||
| "channel": channel, | ||
| "data": data | ||
| "data": data, | ||
| "skip_history": skip_history, | ||
| } | ||
| if uid: | ||
| params['uid'] = uid | ||
| return params | ||
| @staticmethod | ||
| def get_broadcast_params(channels, data, uid=None): | ||
| def get_broadcast_params(channels, data, skip_history=False): | ||
| params = { | ||
| "channels": channels, | ||
| "data": data | ||
| "data": data, | ||
| "skip_history": skip_history, | ||
| } | ||
| if uid: | ||
| params['uid'] = uid | ||
| return params | ||
| @staticmethod | ||
| def get_unsubscribe_params(user, channel=None): | ||
| params = {"user": user} | ||
| if channel: | ||
| params["channel"] = channel | ||
| def get_subscribe_params(user, channel, client=None): | ||
| params = { | ||
| "user": user, | ||
| "channel": channel | ||
| } | ||
| if client: | ||
| params["client"] = client | ||
| return params | ||
| @staticmethod | ||
| def get_disconnect_params(user): | ||
| return { | ||
| def get_unsubscribe_params(user, channel, client=None): | ||
| params = { | ||
| "user": user, | ||
| "channel": channel | ||
| } | ||
| if client: | ||
| params["client"] = client | ||
| return params | ||
| @staticmethod | ||
| def get_disconnect_params(user, client=None): | ||
| params = { | ||
| "user": user | ||
| } | ||
| if client: | ||
| params["client"] = client | ||
| return params | ||
@@ -178,3 +166,3 @@ @staticmethod | ||
| @staticmethod | ||
| def get_history_params(channel): | ||
| def get_presence_stats_params(channel): | ||
| return { | ||
@@ -185,2 +173,16 @@ "channel": channel | ||
| @staticmethod | ||
| def get_history_params(channel, limit=0, since=None, reverse=False): | ||
| params = { | ||
| "channel": channel, | ||
| "limit": limit, | ||
| "reverse": reverse, | ||
| } | ||
| if since: | ||
| params["since"] = { | ||
| "offset": since["offset"], | ||
| "epoch": since["epoch"] | ||
| } | ||
| return params | ||
| @staticmethod | ||
| def get_history_remove_params(channel): | ||
@@ -192,4 +194,6 @@ return { | ||
| @staticmethod | ||
| def get_channels_params(): | ||
| return {} | ||
| def get_channels_params(pattern=""): | ||
| return { | ||
| "pattern": pattern | ||
| } | ||
@@ -202,3 +206,4 @@ @staticmethod | ||
| if self._messages: | ||
| raise ClientNotEmpty("client command buffer not empty, send commands or reset client") | ||
| raise ClientNotEmpty( | ||
| "client command buffer not empty, send commands or reset client") | ||
@@ -212,23 +217,33 @@ def _send_one(self): | ||
| def publish(self, channel, data, uid=None): | ||
| def publish(self, channel, data, skip_history=False): | ||
| self._check_empty() | ||
| self.add("publish", self.get_publish_params(channel, data, uid=uid)) | ||
| self._send_one() | ||
| return | ||
| self.add("publish", self.get_publish_params( | ||
| channel, data, skip_history=skip_history)) | ||
| result = self._send_one() | ||
| return result | ||
| def broadcast(self, channels, data, uid=None): | ||
| def broadcast(self, channels, data, skip_history=False): | ||
| self._check_empty() | ||
| self.add("broadcast", self.get_broadcast_params(channels, data, uid=uid)) | ||
| self.add("broadcast", self.get_broadcast_params( | ||
| channels, data, skip_history=skip_history)) | ||
| result = self._send_one() | ||
| return result | ||
| def subscribe(self, user, channel, client=None): | ||
| self._check_empty() | ||
| self.add("subscribe", self.get_subscribe_params( | ||
| user, channel, client=client)) | ||
| self._send_one() | ||
| return | ||
| def unsubscribe(self, user, channel=None): | ||
| def unsubscribe(self, user, channel, client=None): | ||
| self._check_empty() | ||
| self.add("unsubscribe", self.get_unsubscribe_params(user, channel=channel)) | ||
| self.add("unsubscribe", self.get_unsubscribe_params( | ||
| user, channel, client=client)) | ||
| self._send_one() | ||
| return | ||
| def disconnect(self, user): | ||
| def disconnect(self, user, client=None): | ||
| self._check_empty() | ||
| self.add("disconnect", self.get_disconnect_params(user)) | ||
| self.add("disconnect", self.get_disconnect_params(user, client=client)) | ||
| self._send_one() | ||
@@ -243,17 +258,31 @@ return | ||
| def history(self, channel): | ||
| def presence_stats(self, channel): | ||
| self._check_empty() | ||
| self.add("history", self.get_history_params(channel)) | ||
| self.add("presence_stats", self.get_presence_stats_params(channel)) | ||
| result = self._send_one() | ||
| return result["publications"] | ||
| return { | ||
| "num_clients": result["num_clients"], | ||
| "num_users": result["num_users"], | ||
| } | ||
| def history(self, channel, limit=0, since=None, reverse=False): | ||
| self._check_empty() | ||
| self.add("history", self.get_history_params( | ||
| channel, limit=limit, since=since, reverse=reverse)) | ||
| result = self._send_one() | ||
| return { | ||
| "publications": result.get("publications", []), | ||
| "offset": result.get("publications", 0), | ||
| "epoch": result.get("epoch", ""), | ||
| } | ||
| def history_remove(self, channel): | ||
| self._check_empty() | ||
| self.add("history_remove", self.get_history_remove_params(channel)) | ||
| result = self._send_one() | ||
| self._send_one() | ||
| return | ||
| def channels(self): | ||
| def channels(self, pattern=""): | ||
| self._check_empty() | ||
| self.add("channels", self.get_channels_params()) | ||
| self.add("channels", params=self.get_channels_params(pattern=pattern)) | ||
| result = self._send_one() | ||
@@ -260,0 +289,0 @@ return result["channels"] |
+5
-5
| Metadata-Version: 1.1 | ||
| Name: cent | ||
| Version: 3.0.1 | ||
| Summary: Python library to communicate with Centrifugo API | ||
| Version: 4.0.0 | ||
| Summary: Python library to communicate with Centrifugo v3 HTTP API | ||
| Home-page: https://github.com/centrifugal/cent | ||
@@ -10,8 +10,6 @@ Author: Alexandr Emelin | ||
| Download-URL: https://github.com/centrifugal/cent | ||
| Description: Python library to communicate with Centrifugo API | ||
| Description: Python library to communicate with Centrifugo v3 HTTP API | ||
| Platform: UNKNOWN | ||
| Classifier: Development Status :: 5 - Production/Stable | ||
| Classifier: Programming Language :: Python | ||
| Classifier: Programming Language :: Python :: 2.6 | ||
| Classifier: Programming Language :: Python :: 2.7 | ||
| Classifier: Programming Language :: Python :: 3.3 | ||
@@ -22,2 +20,4 @@ Classifier: Programming Language :: Python :: 3.4 | ||
| Classifier: Programming Language :: Python :: 3.7 | ||
| Classifier: Programming Language :: Python :: 3.8 | ||
| Classifier: Programming Language :: Python :: 3.9 | ||
| Classifier: Environment :: Console | ||
@@ -24,0 +24,0 @@ Classifier: Intended Audience :: Developers |
+20
-22
| CENT | ||
| ==== | ||
| Python tools to communicate with Centrifugo HTTP API. Python 2.6, Python 2.7 and Python >= 3.3 supported. | ||
| Python tools to communicate with Centrifugo v3 HTTP API. Python >= 3.3 supported. | ||
@@ -14,9 +14,9 @@ To install run: | ||
| Cent v3.0.0 and higher works only with Centrifugo v2. | ||
| **Cent v4.0.0 and higher works only with Centrifugo v3**. | ||
| If you need to work with Centrifugo v1 then use Cent [v2.1.0](https://github.com/centrifugal/cent/tree/v2.1.0) | ||
| If you need to work with Centrifugo v2 then use Cent v3 | ||
| ### High-level library API | ||
| First see [available API methods in documentation](https://centrifugal.github.io/centrifugo/server/api/). | ||
| First see [available API methods in documentation](https://centrifugal.github.io/centrifugo/server/http_api/). | ||
@@ -28,3 +28,3 @@ This library contains `Client` class to send messages to Centrifugo from your python-powered backend: | ||
| url = "http://localhost:8000" | ||
| url = "http://localhost:8000/api" | ||
| api_key = "XXX" | ||
@@ -41,13 +41,12 @@ | ||
| # other available methods | ||
| client.unsubscribe("USER_ID") | ||
| client.disconnect("USER_ID") | ||
| messages = client.history("public:chat") | ||
| clients = client.presence("public:chat") | ||
| client.unsubscribe("user_id", "channel") | ||
| client.disconnect("user_id") | ||
| history = client.history("public:chat") | ||
| presence = client.presence("public:chat") | ||
| channels = client.channels() | ||
| stats = client.info() | ||
| info = client.info() | ||
| 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`. | ||
| `publish`, `disconnect`, `unsubscribe`, `history_remove` return `None` in case of success. Each of this commands can raise an instance of `CentException`. | ||
@@ -59,3 +58,3 @@ I.e.: | ||
| client = Client("http://localhost:8000", api_key="XXX", timeout=1) | ||
| client = Client("http://localhost:8000/api", api_key="XXX", timeout=1) | ||
| try: | ||
@@ -74,3 +73,2 @@ client.publish("public:chat", {"input": "test"}) | ||
| ### Low-level library API: | ||
@@ -83,3 +81,3 @@ | ||
| client = Client("http://localhost:8000", api_key="XXX", timeout=1) | ||
| client = Client("http://localhost:8000/api", api_key="XXX", timeout=1) | ||
@@ -98,3 +96,3 @@ params = { | ||
| else: | ||
| print result | ||
| print(result) | ||
| ``` | ||
@@ -116,10 +114,10 @@ | ||
| * address - Centrifugo address | ||
| * 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. | ||
| * `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. |
+5
-7
@@ -12,8 +12,6 @@ import os | ||
| requirements = ['requests'] | ||
| if sys.version_info[:2] in ((2, 6),): | ||
| requirements.append('argparse>=1.2.1') | ||
| def long_description(): | ||
| return "Python library to communicate with Centrifugo API" | ||
| return "Python library to communicate with Centrifugo v3 HTTP API" | ||
@@ -23,4 +21,4 @@ | ||
| name='cent', | ||
| version='3.0.1', | ||
| description="Python library to communicate with Centrifugo API", | ||
| version='4.0.0', | ||
| description="Python library to communicate with Centrifugo v3 HTTP API", | ||
| long_description=long_description(), | ||
@@ -42,4 +40,2 @@ url='https://github.com/centrifugal/cent', | ||
| 'Programming Language :: Python', | ||
| 'Programming Language :: Python :: 2.6', | ||
| 'Programming Language :: Python :: 2.7', | ||
| 'Programming Language :: Python :: 3.3', | ||
@@ -50,2 +46,4 @@ 'Programming Language :: Python :: 3.4', | ||
| 'Programming Language :: Python :: 3.7', | ||
| 'Programming Language :: Python :: 3.8', | ||
| 'Programming Language :: Python :: 3.9', | ||
| 'Environment :: Console', | ||
@@ -52,0 +50,0 @@ 'Intended Audience :: Developers', |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
15447
7.32%292
10.19%