Skip to main content

aioworker

A Python worker running over asyncio

Build Status python version License codecov

Requirements

python 3.8+

Installation

pip install aioworker

Usage

import asyncio

from aioworker import Service, Worker

async def task_1(loop):
    while True:
        print('Hello world')
        await asyncio.sleep(2)


if __name__ == '__main__':
    #  Run the server using 1 worker processes.
    Worker(tasks=[task_1]).run(workers=1)

or run tasks and the webserver

import asyncio

from aioworker import Service, Worker


async def sleeping(loop):
    while True:
        print('Sleeping for 2 seconds...')
        await asyncio.sleep(2)


async def on_client_connect(reader, writer):
    """
    Read up tp 300 bytes of TCP. This could be parsed usign the HTTP protocol for example
    """
    data = await reader.read(300)
    print(f'TCP Server data received: {data} \n')
    writer.write(data)
    await writer.drain()
    writer.close()


if __name__ == '__main__':
    # Run the server using 1 worker processes.
    Worker(
        tasks=[sleeping],
        web_server_config={
            'client_connected_cb': on_client_connect,
        },
    )).run(workers=1)

How to stop the worker

ctrl+c

Default values

Variable Default
TCP server host 0.0.0.0
TPC server port 8888

Examples

  1. Hello world
  2. TCP Server
  3. Kafka Consumer

Development

  1. Clone this repo
  2. Run poetry install
  3. Test using ./scripts/test
  4. Lint automatically using ./scripts/lint

Release files for aioworker 0.2.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 aioworker 0.2.0
File Size Uploaded
aioworker-0.2.0.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aioworker 0.2.0
File Interpreter ABI Platform
aioworker-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.9 kB

Release files / aioworker-0.2.0.tar.gz

Download URL aioworker-0.2.0.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e9e6a3bba7b2c0cc93901f844fba8253a0e7f7e375c3721edbf64d6377f1977b
BLAKE2b-256 checksum
How to use checksums
f0fa0d4c245e61ddcd970de34cbfed6ca7153d691160b66b1d83b2ce7e8d8e8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.2 CPython/3.8.1 Darwin/17.7.0

Release files / aioworker-0.2.0-py3-none-any.whl

Download URL aioworker-0.2.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57e39360366b437f7f1caefc07691cec33d14e2051d12b81527fb22c9abd3b25
BLAKE2b-256 checksum
How to use checksums
6ab8b071746f4fa4fc8b587605e773bbb87b1e1b61f3796a231e80e55d87e624
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.2 CPython/3.8.1 Darwin/17.7.0

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

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