Skip to main content

Shared helpers library for Bizone projects.

Project description

bizone-cloud-helpers

Reusable helpers and decorators shared across Bizone Python projects. Designed for FastAPI applications running in cloud environments (AWS, Azure, GCP).

Features

  • Asynchronous Task Processing: @large_task decorator to turn heavy endpoints into background tasks with callbacks and cross-process idempotency.
  • Concurrency Control: @limit_concurrency decorator for sync functions to prevent resource exhaustion and manage execution timeouts.
  • Cloud File Management: Unified interface for S3, Azure Blob Storage, Google Cloud Storage, and local files with built-in caching (FileCacheManager) and uploading (RemoteUploader).
  • Idempotency: Cross-process file-based locking to ensure tasks with the same X-call-id aren't executed multiple times concurrently.

Installation

From PyPI

pip install bizone-cloud-helpers==0.1.3

The source repository can remain private. Client projects should consume published release artifacts from PyPI instead of installing from Git.

Usage

1. Asynchronous Tasks with Callbacks

Use @large_task to handle long-running requests. It automatically responds with 202 Accepted and runs the function in the background, POSTing the result back to a callback URL.

from bizone_cloud_helpers.async_task import large_task

@app.post("/process")
@large_task(callback_field="callback_url")
async def heavy_computation(data: dict):
    # This runs in background if callback_url is provided in request
    result = perform_work(data)
    return {"status": "done", "result": result}

Support for:

  • Idempotency via X-call-id header.
  • Automatic result/error reporting via HTTP POST.
  • Context propagation for FastAPI Request.
  • Heartbeat timer: Sends PUT pings to the caller during long tasks. Can be overridden via X-heartbeat-interval header (minimum 1s).
  • Concurrency control: Limit how many background instances of a task run at once.

2. Concurrency Limiting

Limit how many instances of a sync or async function can run at once.

from bizone_cloud_helpers.concurrency import limit_concurrency

@limit_concurrency(group="cpu_intensive", max_concurrency=2, max_runtime=60)
def compute_heavy_stuff():
    # Only 2 of these will run at a time across the process
    ...

@limit_concurrency(group="io_intensive", max_concurrency=5)
async def async_io_task():
    # Also works for async functions
    await do_something()

3. Remote Files and Caching

Unified access to cloud storage with local caching.

from bizone_cloud_helpers.remote_files import RemoteFileInfo

# Download/Cache a file from S3
info = RemoteFileInfo(
    provider="s3",
    bucket="my-bucket",
    key="path/to/file.txt",
    access_key="...",
    secret_key="..."
)

local_path = info.local_file # Downloads if not cached or expired

Configuration

Environment variables:

  • IDEMPOTENCY_LOCK_DIR: Directory for idempotency locks (default: /tmp/myapp_idemp_locks).
  • BIZONE_CALLBACK: Default base URL for flow callbacks.
  • MAX_CONCURRENCY: Global default concurrency limit.
  • MAX_CONCURRENCY_<GROUP>: Group-specific concurrency limit.
  • FILE_CACHE_DIR: Directory for local file cache.

Development

Running Tests

The project uses pytest for testing.

  1. Install development dependencies:

    pip install -e ".[dev]"
    
  2. Run all tests:

    python -m pytest
    
  3. Run specific test file:

    python -m pytest tests/test_async_task_new.py
    

Building a Release Locally

python -m pip install -e ".[dev]"
python -m pytest
python -m build

The build creates a wheel and source distribution under dist/.

Publishing Releases

Releases are published to public PyPI from GitHub Actions using PyPI Trusted Publishing. No PyPI API token is required in GitHub secrets.

One-time PyPI setup:

  1. Create or claim the bizone-cloud-helpers project on PyPI.
  2. In PyPI project settings, add a Trusted Publisher for GitHub Actions:
    • owner: Bizone-ai
    • repository: bizone-cloud-helpers
    • workflow: release.yml
    • environment: pypi

Release steps:

git checkout main
git pull
python -m pytest
git tag v0.1.3
git push origin v0.1.3

After PyPI publishes the release, client projects can depend on:

bizone-cloud-helpers==0.1.3

License

MIT

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

bizone_cloud_helpers-0.1.3.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

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

bizone_cloud_helpers-0.1.3-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file bizone_cloud_helpers-0.1.3.tar.gz.

File metadata

  • Download URL: bizone_cloud_helpers-0.1.3.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bizone_cloud_helpers-0.1.3.tar.gz
Algorithm Hash digest
SHA256 487b3f9be5d2c0b5aa7614ba19e1e3d2e164f524cd258939371286ff07f5ebda
MD5 72d449c28f44dd1aedcb0871fe4f216d
BLAKE2b-256 7d9a7fe832e55f499591ae4ee437d008c2600ef09ef84e0359bb45c345b86f92

See more details on using hashes here.

Provenance

The following attestation bundles were made for bizone_cloud_helpers-0.1.3.tar.gz:

Publisher: release.yml on Bizone-ai/bizone-cloud-helpers

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

File details

Details for the file bizone_cloud_helpers-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for bizone_cloud_helpers-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4b3bd9264190af101adda389e00ef59621063a3afbb3806953f0decbc0cdd675
MD5 9d4205d142288b7fa2953f3bca83ab90
BLAKE2b-256 6df02ecadee8fbc776682391cfb858dab2c3aa50b5d6173c485c1282a6ebb80a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bizone_cloud_helpers-0.1.3-py3-none-any.whl:

Publisher: release.yml on Bizone-ai/bizone-cloud-helpers

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