Skip to main content

Database storage backends for the Jobify framework

Project description

Database storage backends for Jobify

Downloads Package version Supported Python versions

jobify-db provides database storage backends for the Jobify framework. It features:

  • PostgreSQL support via asyncpg and psycopg drivers
  • MongoDB support via motor driver
  • MySQL support via aiomysql driver
  • Accepts either a connection string or an externally managed pool/client
  • Automatic table/collection creation on startup

Installation

Install with the driver you need:

pip install jobify-db[asyncpg]
pip install jobify-db[psycopg]
pip install jobify-db[motor]
pip install jobify-db[aiomysql]

Or with uv:

uv add "jobify-db[asyncpg]"
uv add "jobify-db[psycopg]"
uv add "jobify-db[motor]"
uv add "jobify-db[aiomysql]"

How to use

PostgreSQL with asyncpg

import asyncio

from jobify import Jobify

from jobify_db.postgresql.asyncpg import AsyncpgStorage

app = Jobify(
    storage=AsyncpgStorage(dsn="postgresql://user:password@localhost:5432/mydb"),
)


@app.task(cron="*/5 * * * *")
async def my_task() -> None:
    print("Running periodic task every 5 minutes")


async def main() -> None:
    async with app:
        await app.wait_all()


if __name__ == "__main__":
    asyncio.run(main())

PostgreSQL with psycopg

import asyncio

from jobify import Jobify

from jobify_db.postgresql.psycopg import PsycopgStorage

app = Jobify(
    storage=PsycopgStorage(
        conninfo="postgresql://user:password@localhost:5432/mydb",
    ),
)


@app.task(cron="*/1 * * * *")
async def health_check() -> None:
    print("Health check passed")


async def main() -> None:
    async with app:
        await app.wait_all()


if __name__ == "__main__":
    asyncio.run(main())

MongoDB with motor

import asyncio

from jobify import Jobify

from jobify_db.mongodb.motor import MotorStorage

app = Jobify(
    storage=MotorStorage(
        uri="mongodb://localhost:27017",
        database_name="my_app",
    ),
)


@app.task(cron="0 9 * * 1")
async def weekly_report() -> None:
    print("Generating weekly report every Monday at 9 AM")


async def main() -> None:
    async with app:
        await app.wait_all()


if __name__ == "__main__":
    asyncio.run(main())

MySQL with aiomysql

import asyncio

from jobify import Jobify

from jobify_db.mysql.aiomysql import AiomysqlStorage

app = Jobify(
    storage=AiomysqlStorage(
        host="localhost",
        port=3306,
        user="root",
        password="password",
        db="mydb",
    ),
)


@app.task(cron="*/10 * * * *")
async def sync_data() -> None:
    print("Syncing data every 10 minutes")


async def main() -> None:
    async with app:
        await app.wait_all()


if __name__ == "__main__":
    asyncio.run(main())

Using an external pool/client

You can pass an externally managed pool or client instead of a connection string. This is useful when you want to share the pool across multiple components.

import asyncio

import asyncpg
from jobify import Jobify

from jobify_db.postgresql.asyncpg import AsyncpgStorage

DSN = "postgresql://user:password@localhost:5432/mydb"


async def main() -> None:
    pool = await asyncpg.create_pool(dsn=DSN, min_size=2, max_size=20)

    app = Jobify(storage=AsyncpgStorage(pool=pool))

    @app.task(cron="0 3 * * *")
    async def nightly_cleanup() -> None:
        print("Running nightly cleanup")

    async with app:
        await app.wait_all()


if __name__ == "__main__":
    asyncio.run(main())

The same pattern works for PsycopgStorage(pool=pool), MotorStorage(client=client), and AiomysqlStorage(pool=pool).

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

jobify_db-0.0.1.tar.gz (169.4 kB view details)

Uploaded Source

Built Distribution

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

jobify_db-0.0.1-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file jobify_db-0.0.1.tar.gz.

File metadata

  • Download URL: jobify_db-0.0.1.tar.gz
  • Upload date:
  • Size: 169.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for jobify_db-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a0a42a658c98fc9db2916e0e72a3b392ac2a403e4483d72a10706b0683cf17eb
MD5 086e0c336d32883b4b8d4138406826f2
BLAKE2b-256 22a75b27028e3139897a65c23a0f4625ca8b023b297d85d0dc8b47910ef4b84e

See more details on using hashes here.

File details

Details for the file jobify_db-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: jobify_db-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for jobify_db-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f1cfe4af7f276bc1491eb4f755bbdebe262ef4e6708db5a834ed246b525d468b
MD5 1e63bb60f25368af2a5b6e91a6e03e49
BLAKE2b-256 ce6a432ae628564685ca2ed920472519e20b41a79debcb4b6d3d9db799234137

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