Skip to main content

Python SDK for cfenv Cloudflare KV environment sync and hot updates

Project description

cfenv Python SDK

Python SDK for reading cfenv flat-mode environment values from Cloudflare KV and applying hot updates.

Install

pip install cfenv-kv-sync-python

For local development:

pip install -e /path/to/cloudflare-kv-env/packages/python-sdk

Recommended with uv:

cd /path/to/cloudflare-kv-env/packages/python-sdk
uv sync
uv run python -m unittest discover -s tests -v

Basic Usage

from cfenv_sdk import CfenvClient

client = CfenvClient(
    account_id="...",
    api_token="...",
    namespace_id="...",
    project="playheads",
    environment="production",
)

snapshot = client.fetch_flat_env()
print(snapshot.entries)

Export

dotenv_text = client.export_dotenv()
json_text = client.export_json()

Hot Update

from cfenv_sdk import CfenvClient

client = CfenvClient(
    account_id="...",
    api_token="...",
    namespace_id="...",
    project="playheads",
    environment="production",
)

def on_update(snapshot, reason):
    print("updated", reason, snapshot.metadata.updated_at, snapshot.metadata.entries_count)
    client.apply_to_process_env(overwrite=True)

def on_error(err):
    print("hot update error:", err)

watcher = client.create_hot_updater(
    on_update=on_update,
    on_error=on_error,
    interval_seconds=30,
    max_interval_seconds=300,
    bootstrap=True,
)
watcher.start()

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

cfenv_kv_sync_python-0.1.0b1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

cfenv_kv_sync_python-0.1.0b1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file cfenv_kv_sync_python-0.1.0b1.tar.gz.

File metadata

  • Download URL: cfenv_kv_sync_python-0.1.0b1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for cfenv_kv_sync_python-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 4300c3621f08c68175986f034f417695a708d14baa3265dc94fbbceaa336aa2c
MD5 bc73a378446eb0c65d6d37765b74bc9a
BLAKE2b-256 cbaf207aff2feada2bb5413a4f1dce99709e83531f1c62ea235ca47312415509

See more details on using hashes here.

File details

Details for the file cfenv_kv_sync_python-0.1.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for cfenv_kv_sync_python-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 a55fc40f55adf31e4315a27a8aa462a613fb7398c2c68d5923d4a08e4f3ff04c
MD5 62ffba4b7d3f82505a658ca8ee121072
BLAKE2b-256 cad4a7d67c0c48355450f66e432464e4f17fc3284836a3be729290dac8556cb5

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