A tiny queue library leveraging asyncio
Project description
kewkew
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa7cd29b0e1000160359f193d429d9a505fb06d92d3756712f83fdde4700edad
|
|
| MD5 |
ca8fa1959daf7088d0b4d182ed4e8e04
|
|
| BLAKE2b-256 |
5e4c807bf7099a593d7b1feb4daaee5554ff1dfb4eabe6e98628454ad6230b46
|
Provenance
The following attestation bundles were made for kewkew-0.1.1.tar.gz:
Publisher:
release.yml on devdupont/kewkew
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kewkew-0.1.1.tar.gz -
Subject digest:
aa7cd29b0e1000160359f193d429d9a505fb06d92d3756712f83fdde4700edad - Sigstore transparency entry: 409344197
- Sigstore integration time:
-
Permalink:
devdupont/kewkew@13c263ee286b54eb67533cbb4448ae3d83fb1dce -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/devdupont
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@13c263ee286b54eb67533cbb4448ae3d83fb1dce -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44cba8e8aff8edce51aa5248b4f086463fbfb39177a83551a99402ec346ca7c2
|
|
| MD5 |
003a76ef98db1397e60cf4593e150904
|
|
| BLAKE2b-256 |
13ab78f18eab16dfe0314bb9818803f778fcbffb2765d932564dee688946e5e0
|
Provenance
The following attestation bundles were made for kewkew-0.1.1-py3-none-any.whl:
Publisher:
release.yml on devdupont/kewkew
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kewkew-0.1.1-py3-none-any.whl -
Subject digest:
44cba8e8aff8edce51aa5248b4f086463fbfb39177a83551a99402ec346ca7c2 - Sigstore transparency entry: 409344199
- Sigstore integration time:
-
Permalink:
devdupont/kewkew@13c263ee286b54eb67533cbb4448ae3d83fb1dce -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/devdupont
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@13c263ee286b54eb67533cbb4448ae3d83fb1dce -
Trigger Event:
release
-
Statement type: