Skip to main content

Sidekiq-compatible Redis client for dispatching background jobs from Python

Project description

python-sidekiq-client

Redis client for dispatching Sidekiq jobs from Python.

Description

python-sidekiq-client lets you enqueue jobs into Redis in the same format Sidekiq expects. It provides:

  • perform_async: push a job for immediate processing
  • perform_in: schedule a job after a delay
  • perform_at: schedule a job at a specific Unix timestamp

All payloads follow Sidekiq’s JSON schema:

{
  "class": "YourWorkerClass",
  "queue": "default",
  "args": [...],
  "jid": "randomhex",
  "created_at": 1234567890.123,
  "enqueued_at": 1234567890.123,
  // plus any extra options you pass (e.g., retry, backtrace)
}

Installation

If published to PyPI:

pip install python-sidekiq-client

Usage

1. Initialize the Client

from sidekiq_client import SidekiqClient

# Option A: pass Redis URL
client = SidekiqClient("redis://localhost:6379/0")

# Option B: pass existing Redis instance
from redis import Redis
redis_conn = Redis(host="localhost", port=6379, db=0)
client = SidekiqClient(redis_conn)

2. Enqueue a Job Immediately

jid = client.perform_async(
    queue="default",
    job_class="EmailWorker",
    args=[{"to": "user@example.com", "subject": "Welcome"}],
    retry=False
)
print(f"Enqueued job with JID: {jid}")
  • Returns the result of LPUSH (new length of queue:default).

3. Schedule a Job After a Delay

# Schedule to run in 30 seconds
client.perform_in(
    seconds_from_now=30,
    queue="low_priority",
    job_class="CleanupWorker",
    args=[{"folder": "/tmp/cache"}],
    retry=True
)
  • Adds the job payload to sorted set schedule with score = now + 30.

4. Schedule a Job at a Specific Time

import time

run_at = time.mktime((2025, 6, 10, 10, 0, 0, 0, 0, 0))
client.perform_at(
    unix_timestamp=run_at,
    queue="reports",
    job_class="DailyReportWorker",
    args=[{"report_date": "2025-06-09"}],
    retry=False
)
  • Adds to schedule set with score = run_at.

API Reference

SidekiqClient(redis: Union[str, Redis])

  • redis: Redis URL string ("redis://host:port/db") or a redis.Redis instance.
  • Internally calls Redis.from_url if a string is provided.

perform_async(queue: str, job_class: str, args: List[Any], **options) -> str

  • queue: Redis list name (e.g. "default").
  • job_class: Worker class name as a string.
  • args: List of JSON-serializable arguments.
  • **options: Any extra keys added to the payload (e.g., retry, backtrace, tags).
  • Returns the job's id

perform_in(seconds_from_now: int, queue: str, job_class: str, args: List[Any], **options) -> str

  • seconds_from_now: Delay in seconds before job is eligible.
  • Other parameters as in perform_async.
  • Adds JSON payload (without "enqueued_at") to schedule sorted set.
  • Returns the job's id

perform_at(unix_timestamp: float, queue: str, job_class: str, args: List[Any], **options) -> str

  • unix_timestamp: Exact Unix time when job should run.
  • Other parameters as in perform_async.
  • Adds to schedule set with given score.
  • Returns the job's id

Examples

import time
from sidekiq_client import SidekiqClient

client = SidekiqClient("redis://localhost:6379/0")

# 1. Immediate job
jid = client.perform_async(
    queue="default",
    job_class="EmailWorker",
    args=[{"to": "user@example.com"}],
    retry=False
)
print(f"JID={jid}")

# 2. Schedule in 10 seconds
client.perform_in(
    seconds_from_now=10,
    queue="notifications",
    job_class="PushNotifWorker",
    args=[{"user_id": 42}]
)

# 3. Schedule at fixed time
target = time.mktime((2025,6,5,15,0,0,0,0,0))
client.perform_at(
    unix_timestamp=target,
    queue="reports",
    job_class="GenerateReportWorker",
    args=[{"report_id":101}],
    retry=False
)

Running Tests

  1. Ensure Redis is running on localhost:6379
  2. Install pytest:
    pip install pytest
    
  3. Run tests:
    pytest
    

Contributing

  1. Fork repository
  2. Create a branch
  3. Commit changes:
  4. Push branch and open a Pull Request.

Please include tests and keep changes focused.

License

See LICENSE for details.

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

python_sidekiq_client-0.9.4.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

python_sidekiq_client-0.9.4-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file python_sidekiq_client-0.9.4.tar.gz.

File metadata

  • Download URL: python_sidekiq_client-0.9.4.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for python_sidekiq_client-0.9.4.tar.gz
Algorithm Hash digest
SHA256 8b2da1efb099a3855112b30ea74852b6bc8f64f9400561b0dd4e52c6a81383c6
MD5 1d74a98ec6d4240cffa8975fd490996b
BLAKE2b-256 d7d83d36844976577f663fff609f9c5a33d78210a7d5d98bf76f47f9062d478f

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_sidekiq_client-0.9.4.tar.gz:

Publisher: publish.yml on andredriem/python-sidekiq-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_sidekiq_client-0.9.4-py3-none-any.whl.

File metadata

File hashes

Hashes for python_sidekiq_client-0.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e8afa82eb7b084316f123113128cc0c5f0f0a64761577ba6b9f3881170080d27
MD5 1e551a9d066016b0459151b8c2f97d92
BLAKE2b-256 ffcd81eaa1bbaf889e0c31005d4ea66282ac713b9b5a620daed28c5c3e9bb9a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_sidekiq_client-0.9.4-py3-none-any.whl:

Publisher: publish.yml on andredriem/python-sidekiq-client

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