Name | aiopusher JSON |
Version |
0.1.0
JSON |
| download |
home_page | https://github.com/Cikmo/pusher-client |
Summary | An async client for Pusher. Currently in development. Is unusable at the moment. |
upload_time | 2023-06-08 01:17:19 |
maintainer | |
docs_url | None |
author | Christian |
requires_python | >=3.8,<4.0 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# aiopusher
[![PyPI](https://img.shields.io/pypi/v/aiopusher)](https://pypi.org/project/aiopusher/)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/pusher-client.svg)](https://pypi.org/project/pusher-client/)
[![check](https://github.com/tox-dev/tox/actions/workflows/check.yml/badge.svg)](https://github.com/pusher-client/actions/workflows/check.yml)
An async library for subscribing to the Pusher WebSocket protocol.
## Installation
You can install `aiopusher` via pip from PyPI:
```bash
pip install aiopusher
```
Or with [Poetry](https://python-poetry.org/):
```bash
poetry add aiopusher
```
## Usage
Here are some examples of using `aiopusher`:
```python
import asyncio
from aiopusher import Pusher
async def main():
async with Pusher('<your-app-key>') as client:
channel = await client.subscribe('<channel-name>')
channel.bind('<event-name>', lambda data: print(data))
# Run forever (or until manually stopped)
while True:
await asyncio.sleep(1)
asyncio.run(main())
```
#### Or, if you don't want to use context manager, you can use `connect` and `disconnect` methods:
```python
async def main():
client = Pusher('<your-app-key>')
await client.connect()
channel = await client.subscribe('<channel-name>')
channel.bind('<event-name>', lambda data: print(data))
while True:
await asyncio.sleep(1)
await client.disconnect() # Yes, I know this cannot technically be reached
```
#### You can also use decorators to bind events:
```python
import asyncio
from aiopusher import Pusher
client = Pusher('<your-app-key>')
@client.event('<channel-name>', '<event-name>')
async def handle_event(data):
print(data)
async def main():
await client.connect()
# Run forever (or until manually stopped)
while True:
await asyncio.sleep(1)
asyncio.run(main())
```
#### Connect to different endpoints:
```python
import asyncio
from aiopusher import Pusher
async def main():
options = {
host: 'api.example.com', # default: 'ws.pusherapp.com'
"userAuthentication": {
"endpoint": "/auth",
"transport": "ajax",
}
}
async with Pusher('<your-app-key>', options) as client:
channel = await client.subscribe('<channel-name>')
channel.bind('<event-name>', lambda data: print(data))
# Run forever (or until manually stopped)
while True:
await asyncio.sleep(1)
asyncio.run(main())
```
#### You can also make a singleton client, which can be accessed from anywhere in your code:
```python
import asyncio
from aiopusher import Pusher, SingletonClient
async def main():
client = Pusher('<your-app-key>')
SingletonClient.set_client(client)
await client.connect()
channel = await SingletonClient.get_client().subscribe('<channel-name>')
channel.bind('<event-name>', lambda data: print(data))
while True:
await asyncio.sleep(1)
```
---
## Development
To get started with development, you can clone the repository and install the dependencies. [Poetry](https://python-poetry.org/) is used to manage the dependencies, so you can install it with `pip install poetry` (or follow the instructions on the Poetry website) and then run `poetry install` to install the dependencies.
## Testing
If you want to run the tests locally, it should be known that the tests require multiple python versions to be installed. The easiest way to do this is to use [pyenv](https://github.com/pyenv/pyenv).
Once you have pyenv installed, you can run `pyenv install` to install the required versions of python (as specified in the `.python-version` file). Then, you can run `nox` to run the tests.
Raw data
{
"_id": null,
"home_page": "https://github.com/Cikmo/pusher-client",
"name": "aiopusher",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "Christian",
"author_email": "contact@komodo.link",
"download_url": "https://files.pythonhosted.org/packages/41/7f/842bc2bf690b2293e0665626effb87367cdd463b925a3c4d61977aef9e20/aiopusher-0.1.0.tar.gz",
"platform": null,
"description": "# aiopusher\n\n[![PyPI](https://img.shields.io/pypi/v/aiopusher)](https://pypi.org/project/aiopusher/)\n[![Supported Python versions](https://img.shields.io/pypi/pyversions/pusher-client.svg)](https://pypi.org/project/pusher-client/)\n[![check](https://github.com/tox-dev/tox/actions/workflows/check.yml/badge.svg)](https://github.com/pusher-client/actions/workflows/check.yml)\n\nAn async library for subscribing to the Pusher WebSocket protocol.\n\n## Installation\n\nYou can install `aiopusher` via pip from PyPI:\n\n```bash\npip install aiopusher\n```\n\nOr with [Poetry](https://python-poetry.org/):\n\n```bash\npoetry add aiopusher\n```\n\n## Usage\n\nHere are some examples of using `aiopusher`:\n\n```python\nimport asyncio\nfrom aiopusher import Pusher\n\nasync def main():\n async with Pusher('<your-app-key>') as client:\n channel = await client.subscribe('<channel-name>')\n channel.bind('<event-name>', lambda data: print(data))\n\n # Run forever (or until manually stopped)\n while True:\n await asyncio.sleep(1)\n\nasyncio.run(main())\n```\n\n#### Or, if you don't want to use context manager, you can use `connect` and `disconnect` methods:\n\n```python\nasync def main():\n client = Pusher('<your-app-key>')\n await client.connect()\n\n channel = await client.subscribe('<channel-name>')\n channel.bind('<event-name>', lambda data: print(data))\n\n while True:\n await asyncio.sleep(1)\n \n await client.disconnect() # Yes, I know this cannot technically be reached\n```\n\n#### You can also use decorators to bind events:\n\n```python\nimport asyncio\nfrom aiopusher import Pusher\n\nclient = Pusher('<your-app-key>')\n\n@client.event('<channel-name>', '<event-name>')\nasync def handle_event(data):\n print(data)\n\nasync def main():\n await client.connect()\n\n # Run forever (or until manually stopped)\n while True:\n await asyncio.sleep(1)\n\nasyncio.run(main())\n```\n\n#### Connect to different endpoints:\n\n```python\nimport asyncio\nfrom aiopusher import Pusher\n\nasync def main():\n options = {\n host: 'api.example.com', # default: 'ws.pusherapp.com'\n \"userAuthentication\": {\n \"endpoint\": \"/auth\",\n \"transport\": \"ajax\",\n }\n }\n\n async with Pusher('<your-app-key>', options) as client:\n channel = await client.subscribe('<channel-name>')\n channel.bind('<event-name>', lambda data: print(data))\n\n # Run forever (or until manually stopped)\n while True:\n await asyncio.sleep(1)\n\nasyncio.run(main())\n```\n\n#### You can also make a singleton client, which can be accessed from anywhere in your code:\n\n```python\nimport asyncio\nfrom aiopusher import Pusher, SingletonClient\n\nasync def main():\n client = Pusher('<your-app-key>')\n SingletonClient.set_client(client)\n await client.connect()\n\n channel = await SingletonClient.get_client().subscribe('<channel-name>')\n channel.bind('<event-name>', lambda data: print(data))\n\n while True:\n await asyncio.sleep(1)\n```\n\n---\n\n## Development\nTo get started with development, you can clone the repository and install the dependencies. [Poetry](https://python-poetry.org/) is used to manage the dependencies, so you can install it with `pip install poetry` (or follow the instructions on the Poetry website) and then run `poetry install` to install the dependencies.\n\n\n## Testing\nIf you want to run the tests locally, it should be known that the tests require multiple python versions to be installed. The easiest way to do this is to use [pyenv](https://github.com/pyenv/pyenv).\n\nOnce you have pyenv installed, you can run `pyenv install` to install the required versions of python (as specified in the `.python-version` file). Then, you can run `nox` to run the tests.",
"bugtrack_url": null,
"license": "MIT",
"summary": "An async client for Pusher. Currently in development. Is unusable at the moment.",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/Cikmo/pusher-client",
"Repository": "https://github.com/Cikmo/pusher-client"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9280873dadc965c8b779c4edbcf3ac8a1880731f2caaaadcc8b7847903f07672",
"md5": "b00415081d50ca0e6785fcdd89909e90",
"sha256": "a2f32ffe05c2af50ed2ffaf9dde56e0476ab2da6a3082161b9de176ef7170c70"
},
"downloads": -1,
"filename": "aiopusher-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b00415081d50ca0e6785fcdd89909e90",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 3202,
"upload_time": "2023-06-08T01:17:18",
"upload_time_iso_8601": "2023-06-08T01:17:18.096012Z",
"url": "https://files.pythonhosted.org/packages/92/80/873dadc965c8b779c4edbcf3ac8a1880731f2caaaadcc8b7847903f07672/aiopusher-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "417f842bc2bf690b2293e0665626effb87367cdd463b925a3c4d61977aef9e20",
"md5": "5fa9ef06c26a26434855d9146dfe73ac",
"sha256": "ab990f3c248aa54b01deb6b0c1a4497018ba9666bd5e27aeeedcee4ea54d2c91"
},
"downloads": -1,
"filename": "aiopusher-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "5fa9ef06c26a26434855d9146dfe73ac",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 2959,
"upload_time": "2023-06-08T01:17:19",
"upload_time_iso_8601": "2023-06-08T01:17:19.725473Z",
"url": "https://files.pythonhosted.org/packages/41/7f/842bc2bf690b2293e0665626effb87367cdd463b925a3c4d61977aef9e20/aiopusher-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-08 01:17:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Cikmo",
"github_project": "pusher-client",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "aiopusher"
}