Skip to main content

Background jobs on Kubernetes

Project description

Kubicle

Python background jobs on Kubernetes

-> No runtime dependencies, simply run Python functions on Kubernetes and get the results back.

Installation

pip install kubicle

Usage

Define a python function with inputs and an output that use pydantic BaseModel

from pydantic import BaseModel

class Foo(BaseModel):
    a: int
    b: str

class Bar(BaseModel):
    c: float
    d: bool


def call_me_remote(foo: Foo) -> Bar:
    ...

Run as a Kubernetes job

from kubicle import Runner

os.environ["JOB_IMG"] = "foo/bar:latest"

runner = Runner()

job = runner.run(call_me_remote, Foo(a=1, b="hello"))

Wait for the job to finish

from kubicle import JobStatus

while True:
    job.refresh()
    if job.status == JobStatus.FINISHED:
        break

Get the result

bar = Bar.model_validate_json(job.result)

Local

When in development it can be handy to run the job locally.

Do this by setting env var JOB_LOCAL=true or passing the parameter on object creation Runner(local=true) and the job will execute using multiprocessing.

Backends

Job storage can be backed by:

  • Sqlite
  • Postgresql

Sqlite will be used by default. To use postgres simply configure the env vars:

DB_TYPE=postgres
DB_NAME=jobs
DB_HOST=localhost
DB_USER=postgres
DB_PASS=abc123

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

kubicle-0.1.28.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

kubicle-0.1.28-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file kubicle-0.1.28.tar.gz.

File metadata

  • Download URL: kubicle-0.1.28.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.1 Darwin/23.3.0

File hashes

Hashes for kubicle-0.1.28.tar.gz
Algorithm Hash digest
SHA256 ccc1b6baf4eefe597343b5fb9222b73e271400e0324584875f5cafc8f481fa06
MD5 73ab4174333db895be86f7033417c68c
BLAKE2b-256 575ad78081a8836c111018df51c68f59d01788245143be5e83616cb9e8b437ba

See more details on using hashes here.

File details

Details for the file kubicle-0.1.28-py3-none-any.whl.

File metadata

  • Download URL: kubicle-0.1.28-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.1 Darwin/23.3.0

File hashes

Hashes for kubicle-0.1.28-py3-none-any.whl
Algorithm Hash digest
SHA256 3581d377a8d6262039cea6b1906197307db0ab3f8ae79c011d9c1bd800566232
MD5 d63cb8492dbdb9c3f51eab15f4e5d167
BLAKE2b-256 57a4f59310323b506422661b22e47c2d368d34eeb09019710f45c2d47222757c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page