Skip to main content

Cloud native framework for building event driven applications in Python.

Project description

Cloud native framework for building event driven applications in Python

Tests Build License Python Format PyPi Code Style security: bandit Ruff

Note: This package is under active development and is not recommended for production use


Version: 0.1.20

Documentation: https://performancemedia.github.io/eventiq/

Repository: https://github.com/performancemedia/eventiq


About

The package utilizes anyio and pydantic as the only required dependencies. For messages Cloud Events format is used. Service can be run as standalone processes, or included into starlette (e.g. FastAPI) applications.

Installation

pip install eventiq

Multiple broker support (in progress)

  • Stub (in memory using asyncio.Queue for PoC, local development and testing)
  • NATS (with JetStream)
  • Redis Pub/Sub
  • Kafka
  • Rabbitmq
  • Google Cloud PubSub
  • And more coming

Optional Dependencies

  • cli - typer
  • broker of choice: nats, kafka, rabbitmq, redis, pubsub
  • custom message serializers: msgpack, orjson
  • prometheus - Metric exposure via PrometheusMiddleware
  • opentelemetry - tracing support

Motivation

Python has many "worker-queue" libraries and frameworks, such as:

However, those libraries don't provide a pub/sub pattern, useful for creating event driven and loosely coupled systems. Furthermore, the majority of those libraries do not support asyncio. This is why this project was born.

Basic usage

import asyncio
from eventiq import Service, CloudEvent, Middleware
from eventiq.backends.nats.broker import JetStreamBroker


class SendMessageMiddleware(Middleware):
    async def after_broker_connect(self, broker: "Broker") -> None:
        print(f"After service start, running with {broker}")
        await asyncio.sleep(10)
        for i in range(100):
            await broker.publish("test.topic", data={"counter": i})
        print("Published event(s)")

broker = JetStreamBroker(url="nats://localhost:4222")
broker.add_middleware(SendMessageMiddleware())

service = Service(name="example-service", broker=broker)

@service.subscribe("test.topic")
async def example_run(message: CloudEvent):
    print(f"Received Message {message.id} with data: {message.data}")


if __name__ == "__main__":
    service.run()

Scaling

Each message is load-balanced (depending on broker) between all service instances with the same name. To scale number of processes you can use containers (docker/k8s), supervisor, or web server like gunicorn.

Features

  • Modern, asyncio based python 3.8+ syntax
  • Minimal dependencies, only pydantic and python-json-logger are required
  • Automatic message parsing based on type annotations (like FastAPI)
  • Code hot-reload
  • Highly scalable: each service can process hundreds of tasks concurrently, all messages are load balanced between all instances by default
  • Resilient - at least once delivery for all messages by default
  • Customizable & pluggable message encoders (json, msgpack, custom)
  • Json formatted logger
  • Multiple broker support (Nats, Kafka, Rabbitmq, Redis, PubSub, and more coming)
  • Easily extensible via Middlewares and Plugins
  • Cloud Events standard as base message structure (no more python specific *args and **kwargs in messages)
  • AsyncAPI documentation generation from code
  • Twelve factor app approach - stdout logging, configuration through environment variables
  • Out-of-the-box integration with Prometheus (metrics) and OpenTelemetry (tracing)
  • Application bootstrap via .yaml file (see examples/configuration)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eventiq-0.1.20.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

eventiq-0.1.20-py3-none-any.whl (53.3 kB view details)

Uploaded Python 3

File details

Details for the file eventiq-0.1.20.tar.gz.

File metadata

  • Download URL: eventiq-0.1.20.tar.gz
  • Upload date:
  • Size: 36.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for eventiq-0.1.20.tar.gz
Algorithm Hash digest
SHA256 2fb45d096a6106fc147d8ad064e95325f0bc70283fcdd08932399c157917d4a2
MD5 24ad442d5a722a9681f425689b61e81a
BLAKE2b-256 e33025dde9fdb12c12ea9b8c6eb97dfe6c5d10c4e5fcf2520820cb6963407545

See more details on using hashes here.

File details

Details for the file eventiq-0.1.20-py3-none-any.whl.

File metadata

  • Download URL: eventiq-0.1.20-py3-none-any.whl
  • Upload date:
  • Size: 53.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for eventiq-0.1.20-py3-none-any.whl
Algorithm Hash digest
SHA256 eedeba50877187377efa308357f6ca53cacb75865d9be0e06715641542f6e559
MD5 14b9ab4457d57d1766d9f8d9db82d84c
BLAKE2b-256 4797001876e35b71e7d248e3782ff8139e2baeff0efca05d300d1e0e5c7fe033

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page