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.1.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.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kewkew-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 aa7cd29b0e1000160359f193d429d9a505fb06d92d3756712f83fdde4700edad
MD5 ca8fa1959daf7088d0b4d182ed4e8e04
BLAKE2b-256 5e4c807bf7099a593d7b1feb4daaee5554ff1dfb4eabe6e98628454ad6230b46

See more details on using hashes here.

Provenance

The following attestation bundles were made for kewkew-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: kewkew-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 44cba8e8aff8edce51aa5248b4f086463fbfb39177a83551a99402ec346ca7c2
MD5 003a76ef98db1397e60cf4593e150904
BLAKE2b-256 13ab78f18eab16dfe0314bb9818803f778fcbffb2765d932564dee688946e5e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for kewkew-0.1.1-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