Skip to main content

PHX Events

PyPI PyPI - Python Version GitHub

Test PHX Events Lint Python Lint Github Workflows

PHX Events is an AsyncIO library to set up a websocket connection with Phoenix Channels in Python 3.9+.

Check out the phx_event documentation

Installing PHX Events

From Pip

pip install phx-events

From Source

Clone the Git repo and then install the dependencies

pip install -r requirements/core.txt

Use the client in your code:

import asyncio
from concurrent.futures import ThreadPoolExecutor

from phx_events.client import PHXChannelsClient
from phx_events.phx_messages import ChannelMessage, Event, Topic


def print_handler(message: ChannelMessage, client: PHXChannelsClient) -> None:
    client.logger.info(f'DEFAULT: {message=}')


async def async_print_handler(message: ChannelMessage, client: PHXChannelsClient) -> None:
    client.logger.info(f'ASYNC: {message=}')


async def main() -> None:
    token = 'auth_token'
    client: PHXChannelsClient

    with ThreadPoolExecutor() as pool:
        async with PHXChannelsClient(token) as client:
            client.register_event_handler(
                event=Event('event_name'),
                handlers=[
                    print_handler,
                    async_print_handler,
                ],
            )
            client.register_topic_subscription(Topic('topic:subtopic'))

            await client.start_processing(pool)


if __name__ == '__main__':
    asyncio.run(main(), debug=True)

Developing

This project uses pip-tools to manage dependencies.

Before contributing ensure you agree to the DCO. Commits contributed to this project need to be signed in git.

This can be done as follows (Note -s is a shortcut for --signoff) :

git commit --signoff

1. Create a virtualenv

Note: Creating the virtualenv can be done however you want. We will assume you've done created a new virtualenv and activated it from this point.

2. Install pip-tools:

pip install pip-tools

3. Install Dependencies

pip-sync requirements/core.txt requirements/dev.txt 

Metadata

Release files for phx-events 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for phx-events 0.4.1
File Size Uploaded
phx-events-0.4.1.tar.gz 29.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for phx-events 0.4.1
File Interpreter ABI Platform
phx_events-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 42.9 kB

Release files / phx-events-0.4.1.tar.gz

Download URL phx-events-0.4.1.tar.gz
Size 29.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5ffe4c16034af3d82d4be0c41bb0a9de0acfdf4e45156c971facdb4d6fffe10a
BLAKE2b-256 checksum
How to use checksums
7396058251e74e4fadd6d798e6510bf78f6aabdb286a9ce93f1f08d0668c02c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.26.0

Release files / phx_events-0.4.1-py3-none-any.whl

Download URL phx_events-0.4.1-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7093519fa44970443d4bdcbce4dcf1c0f2c8a5afd30e1ab640b422ba4f103b83
BLAKE2b-256 checksum
How to use checksums
3c44707280c9223163cdb881851b97ae6e76913d0656d144bca73f5f6450724d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.26.0

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page