Skip to main content

Python SDK for the Cohestra control plane

Project description

cohestra-sdk

Python SDK for the Cohestra control plane — deploy, scale, rollback, and observe Apache Flink jobs on any Kubernetes cluster.

Install

pip install cohestra-sdk
# with Lambda extras:
pip install cohestra-sdk[lambda]

Quick start

from cohestra_sdk import CohestraClient, DeploymentSpec, ResourceShape

client = CohestraClient("https://cohestra.yourcluster.internal:8080", token="...")

# Register a deployment
client.register("prod", "streaming", "orders", owner="platform-team")

# Get a deployment handle
orders = client.deployment("prod", "streaming", "orders")

# Deploy a new version
orders.deploy(
    DeploymentSpec(
        image_digest="registry.example/orders@sha256:abc123",
        parallelism=8,
        max_parallelism=128,
        resources=ResourceShape(task_manager_cpu=2, task_manager_memory_mib=4096,
                                task_manager_count=2, slots_per_manager=4),
        flink_config={"state.backend.type": "rocksdb"},
    ),
    requester="ci-pipeline",
    approved=True,
)

# Wait for healthy
orders.wait_healthy(timeout=300)

# Check status
print(orders.status())

Operations

orders.scale(16, approved=True, reason="traffic spike")
orders.savepoint()
orders.suspend(reason="maintenance window")
orders.resume()
orders.rollback(target_version=3, reason="regression in v4")
orders.enable_autoscaler()
orders.freeze_autoscaler()

Custom autoscaler

from cohestra_sdk import CohestraClient, AutoscalerBase, ScaleDecision

class MyAutoscaler(AutoscalerBase):
    def evaluate(self, status):
        lag = status["currentVersion"]["healthSummary"]["kafkaLag"]
        current = status["currentVersion"]["spec"]["parallelism"]
        if lag > 100_000 and current < 32:
            return ScaleDecision(current * 2, reason=f"lag={lag}")
        return None

client = CohestraClient("http://localhost:8080")
scaler = MyAutoscaler(client, "prod", "streaming", "orders")
scaler.run_loop(interval=60)

See examples/kafka_lag_autoscaler.py for an AWS Lambda-ready implementation.

Cluster operations

client.freeze_cluster("prod", "streaming", reason="incident")
client.unfreeze_cluster("prod", "streaming")

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

cohestra_sdk-0.1.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

cohestra_sdk-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file cohestra_sdk-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for cohestra_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8921259fb1cb2e2a7c5ac6c02c5b11cde54d772512c16bbb8aea35f008a91b73
MD5 7b54943601c2a34f00cbcd79d3d5b400
BLAKE2b-256 ad6231da0dcd9e5afb9069cb04d7484f2bae4f45aa2dc029bb4e4455cfdf3854

See more details on using hashes here.

Provenance

The following attestation bundles were made for cohestra_sdk-0.1.1.tar.gz:

Publisher: publish-pypi.yml on as791/Cohestra

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

File details

Details for the file cohestra_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cohestra_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cohestra_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2be6a8dc6670e746f0a72c773c061abba7e35a6df4f9dda570c9402b3e9a857
MD5 622815f9aa68d2ec020e764fb0c8148b
BLAKE2b-256 8c592530923afb04fe0bf8feb770dbf6e3722411ebc49e71242f1650ad2adfd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for cohestra_sdk-0.1.1-py3-none-any.whl:

Publisher: publish-pypi.yml on as791/Cohestra

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