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 processingperform_in: schedule a job after a delayperform_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 ofqueue: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
schedulewith 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
scheduleset with score =run_at.
API Reference
SidekiqClient(redis: Union[str, Redis])
redis: Redis URL string ("redis://host:port/db") or aredis.Redisinstance.- Internally calls
Redis.from_urlif 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") toschedulesorted 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
scheduleset 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
- Ensure Redis is running on localhost:6379
- Install
pytest:pip install pytest
- Run tests:
pytest
Contributing
- Fork repository
- Create a branch
- Commit changes:
- Push branch and open a Pull Request.
Please include tests and keep changes focused.
License
See LICENSE for details.
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b2da1efb099a3855112b30ea74852b6bc8f64f9400561b0dd4e52c6a81383c6
|
|
| MD5 |
1d74a98ec6d4240cffa8975fd490996b
|
|
| BLAKE2b-256 |
d7d83d36844976577f663fff609f9c5a33d78210a7d5d98bf76f47f9062d478f
|
Provenance
The following attestation bundles were made for python_sidekiq_client-0.9.4.tar.gz:
Publisher:
publish.yml on andredriem/python-sidekiq-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_sidekiq_client-0.9.4.tar.gz -
Subject digest:
8b2da1efb099a3855112b30ea74852b6bc8f64f9400561b0dd4e52c6a81383c6 - Sigstore transparency entry: 227682180
- Sigstore integration time:
-
Permalink:
andredriem/python-sidekiq-client@577b7987539ce00516b4726fb4d0c3d8873220a4 -
Branch / Tag:
refs/tags/v0.9.4 - Owner: https://github.com/andredriem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@577b7987539ce00516b4726fb4d0c3d8873220a4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file python_sidekiq_client-0.9.4-py3-none-any.whl.
File metadata
- Download URL: python_sidekiq_client-0.9.4-py3-none-any.whl
- Upload date:
- Size: 11.6 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 |
e8afa82eb7b084316f123113128cc0c5f0f0a64761577ba6b9f3881170080d27
|
|
| MD5 |
1e551a9d066016b0459151b8c2f97d92
|
|
| BLAKE2b-256 |
ffcd81eaa1bbaf889e0c31005d4ea66282ac713b9b5a620daed28c5c3e9bb9a2
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_sidekiq_client-0.9.4-py3-none-any.whl -
Subject digest:
e8afa82eb7b084316f123113128cc0c5f0f0a64761577ba6b9f3881170080d27 - Sigstore transparency entry: 227682186
- Sigstore integration time:
-
Permalink:
andredriem/python-sidekiq-client@577b7987539ce00516b4726fb4d0c3d8873220a4 -
Branch / Tag:
refs/tags/v0.9.4 - Owner: https://github.com/andredriem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@577b7987539ce00516b4726fb4d0c3d8873220a4 -
Trigger Event:
push
-
Statement type: