Skip to main content

Minimalistic, embedded task manager.

Project description

Castor

Castor is a minimalistic, embedded task manager built on BeaverDB. It's designed to run background tasks (both process and thread-based) in applications where a complicated, distributed broker like Redis is overkill.

It embraces the minimalistic philosophy of BeaverDB while still being feature-full for the use cases where it makes sense.

Core Philosophy

  • Explicit Over Implicit: The library avoids global state. Configuration is handled through explicit Manager objects, making applications more robust and testable.
  • Single Responsibility: castor is a task queueing and execution library. Nothing else, nothing more.
  • Developer Experience: The API is designed to be intuitive, requiring minimal boilerplate to turn a function into a background task.
  • Decoupled Architecture: The application that enqueues a task is fully separate from the worker process that executes it. They communicate only through the shared database file.
  • Targeted Concurrency: Provides clear, mandatory choices for both I/O-bound (thread) and CPU-bound (process) concurrency models on a per-task basis.

Installation

pip install castor-io

Quickstart

1. Create your application file

# main.py
import time
from beaver import BeaverDB
from castor import Manager

# 1. Setup the manager
db = BeaverDB("tasks.db")
manager = Manager(db)

# 2. Define a background task
@manager.task(mode='thread')
def send_email(recipient: str):
    """Simulates a background I/O task."""
    print(f"-> Sending email to {recipient}...")
    time.sleep(2)
    print(f"<- Email sent to {recipient}.")
    return {"recipient": recipient, "status": "sent"}

# 3. Dispatch the task (if running this file directly)
if __name__ == "__main__":
    print("--- Dispatching background task ---")
    email_task = send_email.delay("alice@example.com")
    print(f"Dispatched email task with ID: {email_task.id}")

    print("\n--- Waiting for result ---")
    result = email_task.join(timeout=5)
    print(f"Result from email task: {result}")
    print("\n--- Example finished ---")

2. Run the worker from your terminal

The worker needs to know where your Manager instance is. You provide this as an import path.

castor main:manager

You will see the worker start and process the task.

Starting server... Ctrl+C to stop.

Alternatively, run in interactive mode to see a rich dashboard with logs and statistics.

castor main:manager -i

3. Run your application

python main.py

You will see tasks being processed in the worker log.

Features

  • Task Decorator: A simple @manager.task decorator to turn any function into a background task.
  • Execution Modes: Explicitly define tasks as thread (for I/O-bound work) or process (for CPU-bound work).
  • Task Handle: Calling .delay() on a task returns a TaskHandle object, allowing you to check the .status() or wait for the result.
  • Synchronous and Asynchronous Results: Block for a result with .join() or wait for it asynchronously with .resolve().
  • Reliable Backend: Uses beaver-db for a simple and reliable file-based persistence layer.
  • CLI Worker: A built-in command-line interface to run the worker server.

Roadmap

This is a work in progress. The immediate roadmap includes:

  • Process-based tasks: While the mode='process' is available in the API, the underlying process pool execution is not yet fully implemented. This is the highest priority.
  • Monitoring UI: A more advanced terminal-based monitoring dashboard for the worker.
  • Retries and error handling: More robust mechanisms for automatic retries and dead-letter queues.

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

castor_io-0.3.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

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

castor_io-0.3.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file castor_io-0.3.1.tar.gz.

File metadata

  • Download URL: castor_io-0.3.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.13

File hashes

Hashes for castor_io-0.3.1.tar.gz
Algorithm Hash digest
SHA256 e197cce6b99e1372c1da2873457f1f6eb220286e4520adeb349a2c4a0507379e
MD5 a6561b286af0a8bbee05e51b4e87aeee
BLAKE2b-256 07640c220104741240593576edcc788351cbe2457e9b636a6a1ca26a28488e84

See more details on using hashes here.

File details

Details for the file castor_io-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: castor_io-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.13

File hashes

Hashes for castor_io-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 17005ea56d2752816157a1c00711d809994098a79402358cbd670fdd7a41f012
MD5 e6f6bc2257d57bec3e4912a5b57d9f61
BLAKE2b-256 08f86bc3443544107a4d28a2b6996f849f41f8d0bcf44bdb1ae5647d6d2652cc

See more details on using hashes here.

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