Skip to main content

kerground

Downloads PyPI

Stupid simple background worker based on python. Kerground is super basic - no need for Redis/RabbitMQ. It does not utilize to much RAM because events are saved in plain old json files.

Quickstart

Install

pip install kerground

In your app folder create a new package called dependencies (you can add this in utils or whatever you consider fit otherwise)

#app/dependencies/kerground.py
from kerground import Kerground

ker = Kerground()

You can set on Kerground the following params:

  • tasks_path - path where the events will be saved by default in "./.kergroundtasks";
  • pool - wait in seconds for pending tasks;

Next register your background workers like:

#some_module_.py
from app.dependencies import ker

@ker.register(ker.MODE.THREAD, max_retries=3)
def convert_files(event: list[str]):
    pass # some heavy duty stuff here

# or just go with the defaults

@ker.register
def convert_files_v2(event: list[str]):
    pass # some heavy duty stuff here

The event must be json serializable!

There are 3 mode available:

  • ker.MODE.THREAD - distribute events with threading.Thread if you have urls to wait;
  • ker.MODE.PROCESS - (default) distribute events with multiprocessing.Process if you have some CPU intensive tasks;
  • ker.MODE.SYNC - distribute events one by one for the func to process;

By default max_retries is 0 you can increase this number if you need to get data from some urls and there is a posibility they will fail.

Now you can send an event to background worker (kerground) like:

#some_other_module_possible_route_handler.py
from app.dependencies import ker

def send_files_for_conversion(files: List[UploadFile]):
    filepaths = [file.filename for file in files]
    msgid = ker.enqueue("convert_files", filepaths)
    return f"Files were sent for conversion with id: {msgid}"

Pass to ker.enqueue the function name you want to call in background along with the json parsable *args and **kwargs. Function ker.enqueue will return an id which you can later inspect for it's status with ker.check_status(msgid).

Prepare the worker.py file:

# ./worker.py
from app.dependencies import ker

if __name__ == "__main__":
    ker.listen()

You can check the example folder which was used for tests.

Dashboard

Kerground offers a small dashboard in which you can see the functions registered and their status count in a table. To see the dashboard create a new file worker_dashboard.py and add the following code:

#./worker_dashboard.py
from app.dependencies import ker

if __name__ == "__main__":
    ker.dashboard()

Go to http://localhost:3030/ to see the dashboard.

The data used to fill the tasks table from the dashboard is taken by calling function: ker.get_current_tasks(). You are free to create a custom endpoint in your choosed web framework and call that func. More features will be added soon.

Submit any questions/issues you have! Fell free to fork it and improve it!

Metadata

Release files for kerground 0.1.1

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

Source distribution (sdist)

Source distribution for kerground 0.1.1
File Size Uploaded Provenance
kerground-0.1.1.tar.gz 6.2 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 12.6 kB

Release files / kerground-0.1.1.tar.gz

Download URL kerground-0.1.1.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8881bce7eaff32801c6d32d1e629bc747b18c3091bbe597622dc53da2481f763
BLAKE2b-256 checksum
How to use checksums
e15751159b6b4e3d99ba9b5c33ba5558447aa017ae041098afbac3c15dc93e20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

Release files / kerground-0.1.1-py3-none-any.whl

Download URL kerground-0.1.1-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3808e3402126abb3eb8113dc486498c538df4f3a04178be6419dcec07761fc02
BLAKE2b-256 checksum
How to use checksums
29a0c66815f2a9fe20ca7cc80f9ff60d5f29a4c2b123ed38219527a5f5d5d845
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

Security for kerground 0.1.1

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.

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