Skip to main content

A tiny queue library leveraging asyncio

Project description

kewkew

PyPI version License

A tiny queue library leveraging asyncio for background tasks or scripting

Install

You can install kewkew via pip.

python -m pip install kewkew

You can also download the kewkew/kew.py source from this repo. There are no external dependencies to worry about.

Usage

The Kew class is meant to be a parent class. At a minimum, the child class needs to implement an async worker method which must do two things:

  • Take a single argument that accepts data from the queue
  • Returns a boolean if the data was processed successfully and can be removed from the queue

Here is a minimum viable implementation.

from kewkew import Kew

class MyKew(Kew):
    async def worker(self, data) -> bool:
        print(data)
        return True

We then have two main ways of using the queue. Kew provides both sync and async methods to add items to the queue and tell the queue to finish processing (for a graceful shutdown).

This first example uses the sync calls so everything can be run in an interactive environment.

from mykew import MyKew

kew = MyKew()
for i in range(100):
    kew.add_sync(i)
kew.finish_sync()

This second example uses the async calls within a coroutine.

import asyncio as aio

async def main():
    kew = MyKew()
    for i in range(100):
        await kew.add(i)
    await kew.finish()

aio.run(main)

You can see this and an async database processing example in the examples folder.

Debug

Python Queues have a tendency to swallow runtime exceptions. You can debug your worker more easily by calling it directly.

import asyncio as aio
from mykew import MyKew

kew = MyKew()
aio.run(kew.worker(1))

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

kewkew-0.1.2.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kewkew-0.1.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file kewkew-0.1.2.tar.gz.

File metadata

  • Download URL: kewkew-0.1.2.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kewkew-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bd7cc55cc85134a887785a1ddd86f57234d747d7f7a45e4e0a93304f313b6f04
MD5 7ab9231bf81f5fcc8f788a889dd29370
BLAKE2b-256 16279381efd018a7184bf02ef4bbdbc36c12104aeda9674a3ec325ed6fb7cb93

See more details on using hashes here.

Provenance

The following attestation bundles were made for kewkew-0.1.2.tar.gz:

Publisher: release.yml on devdupont/kewkew

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kewkew-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: kewkew-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kewkew-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 de3770b6b96b9c17d68195007f180e771939d2ee8a20d584d67f53dd1140fb50
MD5 9e16a1425d75e3ddf6aa155c4d25217f
BLAKE2b-256 a7481286d09b53f217cfce67848b5c417011f90f41ecae2852b37cb261046983

See more details on using hashes here.

Provenance

The following attestation bundles were made for kewkew-0.1.2-py3-none-any.whl:

Publisher: release.yml on devdupont/kewkew

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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