Skip to main content

Pykiq

A sidekiq client library for python 3. It uses a simple redis connection to store jobs in one of sidekiqs redis queues.

Usage

The same redis connection, i.e. server, port and database, must be used as it is already done for sidekiq. You can store it in a pykiq connector object:

import pykiq
import redis

error_handler = pykiq.error.NullErrorHandler()
conn = redis.Redis(name, port, db)
connector = pykiq.connector.RedisConnector.from_existing_connection(error_handler, conn)

This connection can be used to create a pykiq connection:

kiq = pykiq.Sidekiq(connector)

Unfortunately, you cannot use this connection directly, since each job has arguments to process and a queue, in which it is enlisted.

Therefore, an object-oriented approach should be used:

class MyJobs(pykiq.Sidekiq):
    def __init__(self, connector: Connector) -> None:
        super().__init__(connector)
        ...

Queues can be declared directly in the constructor. You must re-use the names of the sidekiq queues.

class MyJobs(pykiq.Sidekiq):
    def __init__(self, connector: Connector) -> None:
        super().__init__(connector)
        urgent_queue = pykiq.SidekiqQueue("urgent", self)

A job can now easily be added:

class MyJobs(pykiq.Sidekiq):
    def __init__(self, connector: Connector) -> None:
        super().__init__(connector)
        urgent_queue = pykiq.SidekiqQueue("urgent", self)
        self.__clean_up = CleanUpJob(urgent_queue)

    @property
    def clean_up(self):
        return self.__clean_up

class CleanUpJob(pykiq.Job):
    def __init__(self, queue: pykiq.SidekiqQueue) -> None:
        super().__init__(queue, "full::name::of::CleanUpJob")

    def clean_up_at(self, time_span: datetime.timedelta, amount: int):
        return super()._perform_in(time_span, amount)

When declaring a new job, the full name of the ruby class including the module namespaces must be added. Each job declares to methods: _perform_in and _perform_async, where the first takes a timedelta to specify a delay. Please note, that the delay must be positive and should respect network latencies.

Any other argument can be added using the variadic argument list and hence a job should declare its own function with arguments.

The usage now is quite simple:

jobs = MyJobs(connector)
jobs.clean_up.clean_up_at(timedelta(minutes=30), 50)

That's it.

License

This is merely a re-write of sidekiq's ruby code in python. Hence the same license for sidekiq and pykiq are used and the library can be freely distributed according to the LGPLv3.

Versioning

This library follows semantic versioning 2.0. Any breaking change will produce a new major release. Versions below 1.0 are considered to have a unstable interface.

Metadata

Release files for pykiq 0.10.3

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

Source distribution (sdist)

Source distribution for pykiq 0.10.3
File Size Uploaded
pykiq-0.10.3.tar.gz 12.0 kB Details

Built distribution (wheel)

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

Total release size: 26.9 kB

Release files / pykiq-0.10.3.tar.gz

Download URL pykiq-0.10.3.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a1645d996bdac7181159795a6a418cd7d714282f10283ba5b10e58e06400dd4f
BLAKE2b-256 checksum
How to use checksums
c311ef289fc64b457ce58afde064328fbb1063810002f535ab833a9eda756f1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

Release files / pykiq-0.10.3-py3-none-any.whl

Download URL pykiq-0.10.3-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28754dfce74c071e343bfdda54b43fa6a386c6c4f17d1f16ea8d5d5a95ca44ee
BLAKE2b-256 checksum
How to use checksums
ae6419bf1d17e6a162b16e8696cf8a26b6417f5808787ca483fac590893ca188
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

Release history Release notifications | RSS feed

This release

0.10.3 This release

2 release files

0.9.0

2 release files

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