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.0.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.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cohestra_sdk-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 d6045004151ff0baf5af74ad198d26a7451e691b880249e9e0ec8379c92f3535
MD5 570e5a1c6ac07c880f4cc5ac0d9d86e7
BLAKE2b-256 fe42ea2ca06eb72bbb2d07c3611901677333abd5d13b4f290ef2691aba7f87c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for cohestra_sdk-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: cohestra_sdk-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8806bd74277abad00ba08b11a7eefb4bae446f9e49727e754c230bc8078705e
MD5 a28abc2af2eb79e277399bd96f5b71cf
BLAKE2b-256 a5b3d68ffe81405bb7a8fac67137d2c2e8b18dd4d6acb26558ef7a8013892b49

See more details on using hashes here.

Provenance

The following attestation bundles were made for cohestra_sdk-0.1.0-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