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 (.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.0.tar.gz (14.9 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.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for castor_io-0.3.0.tar.gz
Algorithm Hash digest
SHA256 648aad030d9d6a30f9a5e3f09331e0949e936d9fe96c7dbe8077119f80fe27a4
MD5 62a015381c095f5724622c2b7bbbdf26
BLAKE2b-256 11f8ad21aff8cc96d3e2f64fdbfcc889d122031f6c08ab6ed99c3a1de6c2649f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for castor_io-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 baf3bca4e07d7e16664c740c7394829b3496d7ab9a953d30c79a09d1d36a41b2
MD5 a8c1a569e0490bc7d4a33751434ce184
BLAKE2b-256 5c300aa0282d12a00d9d3a99a0d9e9fc865b71462a7a43e8f7d1a5004db5c854

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