Skip to main content

asyncio-RED (Redis Event Driven)

Powers your microservices with event driven approach using redis as a backend.

Support both publishing and subscribing using lists, channels and streams.

pydantic is being used for events validation.

s3 can be used for sharing event schemas between services.

Installation

  • pip install asyncio-red

Simple producer

from redis.asyncio import Redis
from asyncio_red import RED, Via, BaseEvent
from pydantic import Field

class EventV1List(BaseEvent):
    key: str = Field(..., title='Key description')
    

class EventV1Channel(BaseEvent):
    key: str = Field(..., title='Key description')
    
    
class EventV1Stream(BaseEvent):
    key: str = Field(..., title='Key description')

    
redis_client = Redis()
red = RED(app_name=str('service_1'), redis_client=redis_client)

red.add_out(
    event=EventV1List,
    via=Via.LIST,
    target_name='events_list'
)

red.add_out(
    event=EventV1Channel,
    via=Via.CHANNELS,
    target_name='events_channel'
)

red.add_out(
    event=EventV1Stream,
    via=Via.STREAMS,
    target_name='events_stream'
)


async def your_awesome_function():
    # dispatch events
    await EventV1List(key='value').dispatch()  # this one will be put to a list
    await EventV1Channel(key='value').dispatch()  # this one will be pushed to a channel
    await EventV1Stream(key='value').dispatch()  # this one will be pushed to a stream

Simple consumer

from redis.asyncio import Redis
from asyncio_red import RED, Via, BaseEvent
from pydantic import Field

class EventV1List(BaseEvent):
    key: str = Field(..., title='Key description')
    

class EventV1Channel(BaseEvent):
    key: str = Field(..., title='Key description')
    
    
class EventV1Stream(BaseEvent):
    key: str = Field(..., title='Key description')
    

redis_client = Redis()
red = RED(app_name=str('service_2'), redis_client=redis_client)


async def event_handler(event):
    print(event)


red.add_in(
    event=EventV1List,
    via=Via.LIST,
    handlers=(event_handler, ),
    list_name="events_list",
)

red.add_in(
    event=EventV1Channel,
    via=Via.CHANNELS,
    handlers=(event_handler, ),
    error_handler=event_handler,
    channel_name="events_channel"
)

red.add_in(
    event=EventV1Stream,
    via=Via.STREAMS,
    handlers=(event_handler, event_handler),
    stream_name="events_stream",
    group_name="events_group",
    consumer_name="consumer_name"
)

await red.run()

Shared events registry

There is a possibility to keep event schemas registry on the S3 and share the schema across different services. You'll need an AWS account and keys with access to S3.

  • Go to app root dir and initialize asyncio-red:
asyncio_red init --app-name=<app name> --s3-bucket=<bucket name>

This will create an initial structure. Define your events at red/registry/<app name>.py:

from pydantic import Field
from asyncio_red.events import BaseEvent


class EventV1List(BaseEvent):
    key: str = Field(..., title='Key description')
    

class EventV1Channel(BaseEvent):
    key: str = Field(..., title='Key description')
    
    
class EventV1Stream(BaseEvent):
    key: str = Field(..., title='Key description')
  • push application events schemas to a registry: asyncio-red push
  • on a different service you can pull shared schemas - do the same steps, e.g. init structure and run asyncio-red pull

Metadata

Release files for asyncio-red 0.3.7

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

Source distribution (sdist)

Source distribution for asyncio-red 0.3.7
File Size Uploaded
asyncio_red-0.3.7.tar.gz 13.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asyncio-red 0.3.7
File Interpreter ABI Platform
asyncio_red-0.3.7-py3-none-any.whl Python 3 none any Details

Total release size: 30.9 kB

Release files / asyncio_red-0.3.7.tar.gz

Download URL asyncio_red-0.3.7.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2c321b5a59ff234a980fcf826a085c7798dca269ae6aef52603773368ce0f149
BLAKE2b-256 checksum
How to use checksums
3aa0012f34529a9f7b220eb0665cd5784f98f72b98c039ec49401f30eb1655de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.12.8 Linux/6.8.0-1017-azure

Release files / asyncio_red-0.3.7-py3-none-any.whl

Download URL asyncio_red-0.3.7-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a93612b7de17cafb1868ff3f471f37b3caddddd1df1c7d75ddca315416207076
BLAKE2b-256 checksum
How to use checksums
4d089932baa39bf7cf85a9d9c3e5e3bd8a6acfceb5e15be62c2d0693122937b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.12.8 Linux/6.8.0-1017-azure

Release history Release notifications | RSS feed

This release

0.3.7 This release

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

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