Skip to main content

Build Status Test Coverage Code style: black PyPI version

O projeto

O projeto tem como objetivo ser um framework para escrever workers assíncronos em python. Por worker entende-se qualquer aplicação que rode por tempo indeterminado e que receba estímulos de várias origens diferentes. Essas orignes podem ser:

  • Uma mensagem em um broker, como RabbitMQ;
  • Um evento vindo se um servidor HTTP, como server side events;
  • Um evento recorrente gerado em um intervalo fixo de tempo;
  • Uma requisição HTTP
  • ...

Documentação: https://b2wdigital.github.io/async-worker/

Exemplos rápidos

Abaixo estão alguns exemplos bem simples que dão uma ideia do projeto e de como fica um código escrito com asyncorker.

Handler HTTP

from aiohttp import web

from asyncworker import App

app = App()


@app.http.get(["/", "/other"])
async def handler():
    return web.json_response({})


app.run()

Esse handler recebe reqisições HTTP (GET) nos seguintes endereços (por padrão): http://127.0.0.1:8080/ e http://127.0.0.1:8080/other

Handler RabbitMQ

from typing import List

from asyncworker import App
from asyncworker.connections import AMQPConnection
from asyncworker.options import Options
from asyncworker.rabbitmq import RabbitMQMessage, AMQPRouteOptions

amqp_conn = AMQPConnection(
    hostname="127.0.0.1",
    username="guest",
    password="guest",
    prefetch_count=1024,
)

app = App(connections=[amqp_conn])


@app.amqp.consume(
    ["queue", "queue-2"], options=AMQPRouteOptions(bulk_size=512)
)
async def handler(messages: List[RabbitMQMessage]):
    print(f"Received {len(messages)} messages")
    for m in messages:
        await amqp_conn.put(
            data=m.body, exchange="other", routing_key="another-routing-key"
        )


@app.run_every(1)
async def produce(app: App):
    await amqp_conn.put(data={"msg": "ok"}, routing_key="queue")


app.run()

Esse handler recebe mensagens das filas queue e queue-2 em lotes de 512 mensagens. Se essas duas filas demorarem mais de 60 segundos para acumular, juntas, 1024 mensagens o handler será chamado imediatamente com a quantidade de mensagens que estiver disponível no momento.

O que esse handler está fazendo é apenas pegar todas as mensagens que ele recebe e enviar para o exchange="", routing_key="queue".

Metadata

Release files for async-worker 0.18.0

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

Source distribution (sdist)

Source distribution for async-worker 0.18.0
File Size Uploaded Provenance Actions
async-worker-0.18.0.tar.gz 26.5 kB Without provenance Details for async-worker-0.18.0.tar.gz

Release files / async-worker-0.18.0.tar.gz

Download URL async-worker-0.18.0.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
811941eae5b1de4140886329729db23321881915f6f7d95b779fb88dd414468f
BLAKE2b-256 checksum
How to use checksums
692267454a2a3ac0a339517546edc5f5c5e8cdae67f4bca39eae5dbf7d65d5be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9

Security for async-worker 0.18.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.18.0 This release

1 release file No provenance

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