Metadata-Version: 2.4
Name: coakka-runtime-python
Version: 3.3.2
Summary: CoAkka Runtime Python connector
Requires-Python: >=3.11
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: 3.11
License-Expression: Apache-2.0
Requires-Dist: coakka-v2-connector==3.3.2
License-File: LICENSE
License-File: NATIVE-LICENSE.md
License-File: PACKAGE-LICENSE.md
License-File: NOTICE
Project-URL: Homepage, https://coakka.io
Project-URL: Funding, https://github.com/sponsors/phuong-tran
Project-URL: Documentation, https://github.com/phuong-tran/coakka-samples/tree/main/docs
Project-URL: Samples, https://github.com/phuong-tran/coakka-samples
Project-URL: Issues, https://github.com/phuong-tran/coakka-samples/issues
Description-Content-Type: text/markdown

# coakka-runtime-python

![CoAkka](https://raw.githubusercontent.com/phuong-tran/coakka-samples/main/docs/common/assets/brand/coakka-logo.png)

**Your work. Your language. Connected.**

Use `coakka-runtime-python` for new projects. Existing applications can keep
`coakka-v2-connector`. Both install names use the `coakka_v2_connector` import.

[CoAkka Portal](https://coakka.io)

## Contents

- [Overview](#overview)
- [Install and quickstart](#install-and-quickstart)
- [Compatibility and versions](#compatibility-and-versions)
  - [Version 3.3.2](#version-332)
- [Upgrade or migrate](#upgrade-or-migrate)
- [Features and guides](#features-and-guides)
  - [Connection strategy](#connection-strategy)
  - [File Lane](#file-lane)
  - [Stream Lane](#stream-lane)
- [Deployment](#deployment)
- [Samples, benchmarks and support](#samples-benchmarks-and-support)
- [Sponsorship](#sponsorship)
- [License](#license)

## Overview

Register a Python handler under a named target and call it from a local
process or from services in other languages. CoAkka Runtime Core owns
admission, routing, delivery and terminal outcomes. The Python connector
exposes those contracts through Python values and context managers.

CoAkka is a polyglot, cross-platform ecosystem. Each product has its own
packages, supported hosts and lifecycle. An application can use one product
or combine them.

**CoAkka Runtime** is an embedded runtime for service-to-service and local
application work across languages and hosts. The application owns its
handlers and business logic. Core handles delivery.

- Named targets route request/reply and one-way events to local or peer
  handlers. Envelopes carry the payload and delivery metadata. Core
  matches replies and enforces request deadlines.
- Bounded queues limit admitted work. Core reports refusals, timeouts
  and structured deadletters when delivery fails.
- Versioned route snapshots let supported hosts update routing live.
  Peer connections use multiplexed TCP by default and can use TLS or
  mutual TLS.
- Health, pressure counters and optional monitoring expose delivery
  behavior. File Lane transfers bulk data and Stream Lane carries
  framed streams.

[Runtime guides](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/README.md) ·
[Messages and routing](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/explanation/runtime-message-and-routing-model.md)

**CoAkka HTTP Runtime** is a full HTTP server and client for browser
frontends, HTTP APIs and upstream services. Select a standalone HTTP/1.1, HTTP/2 or HTTP/3 listener,
or serve buffered requests and replies across all three on one HTTPS port
with the MultiProtocol profile. MultiProtocol serves buffered exchanges.
Use a standalone listener for streaming, SSE or WebSocket. The standalone
feature set includes:

- Bounded admission and backpressure limit active exchanges and resource
  use. Typed outcomes identify overload and resource refusals.
- Static frontend assets, single-page application fallback, file downloads
  and byte ranges, plus optional compression for buffered responses.
- Streaming uploads and responses, Server-Sent Events (SSE), and WebSocket
  sessions over HTTP/1.1.
- Outbound HTTP calls with deadlines and cancellation, TLS and mutual TLS
  where supported by the listener profile, and graceful shutdown.
- Health and effective-configuration inspection, optional monitoring,
  and live route or handler updates on supported profiles.

[HTTP Runtime features and protocol support](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-http-runtime/reference/FEATURES.md) ·
[Serve a frontend and backend](https://github.com/phuong-tran/coakka-publish/blob/main/docs/coakka-http-runtime/explanation/frontend-and-backend.md) ·
[HTTP Runtime for Python](https://github.com/phuong-tran/coakka-publish/blob/main/coakka-http-runtime/python/README.md)

**CoAkka Logger** provides application logging with bounded storage,
explicit admission and delivery outcomes, and observable backpressure.
[Logger guide](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-logger/README.md)

**Optional integrations** include Runtime Addons for tasks such as
acquiring files before File Lane delivery, and HTTP Runtime Inspect for
route inspection and OpenAPI export when a service enables inspection.
[Runtime Addons](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/guides/runtime-addons.md) ·
[HTTP Runtime Inspect](https://github.com/phuong-tran/coakka-publish/blob/main/docs/coakka-http-runtime/inspect/metadata-and-openapi.md)

For example, a checkout service can serve the browser over HTTP and call
a Python pricing handler by target through CoAkka Runtime. The application
owns the handler and pricing logic.
[Run the web demo](https://github.com/phuong-tran/coakka-samples/blob/main/coakka-runtime/scenarios/order-quote-node-python/README.md) ·
[Explore the ecosystem](https://github.com/phuong-tran/coakka-samples/blob/main/docs/common/ecosystem-overview.md)

## Install and quickstart

Use GIL-enabled CPython 3.11 or later. Create a virtual environment and
install the connector from PyPI.

```sh
python -m venv .venv
.venv/bin/python -m pip install --only-binary=:all: coakka-runtime-python==3.3.2
```

On Windows, use `.venv\Scripts\python.exe` in place of `.venv/bin/python`.

Save this example as `first_run.py`. Run it with `.venv/bin/python first_run.py`
or `.venv\Scripts\python.exe first_run.py` on Windows.

```python
from coakka_v2_connector import ConnectorStartSpec, RuntimeHost, local_route


def accept_name(payload: bytes) -> bytes:
    return b"accepted-" + payload


target = "customers.accept"
start_spec = ConnectorStartSpec(
    system_name="customer-app",
    node_id="customer-app-1",
    routes=(local_route(target),),
)

with RuntimeHost.start(start_spec=start_spec) as runtime:
    runtime.register_payload_handler(target, accept_name)
    reply = runtime.ask_payload(
        source="customer-api",
        target=target,
        payload=b"Ada Lovelace",
        timeout_ms=2000,
    )
    print(reply.decode("utf-8"))
```

The handler returns `accepted-Ada Lovelace`. Exiting the `with` block closes
Runtime. [Python first-run sample](https://github.com/phuong-tran/coakka-samples/tree/main/coakka-runtime/python/registry-basic)

## Compatibility and versions

Read a connector version as `MAJOR.MINOR.REVISION`. The first two numbers
identify the Core generation. The last number identifies the connector
revision within that generation.

## Version `3.3.2`

`3.3.2` is revision 2 on Core generation `3.3`.
`coakka-runtime-python==3.3.2` is a metadata-only package that requires
exactly `coakka-v2-connector==3.3.2`. Each platform wheel includes Core 3.3,
build `16bdd692faf918d1a959c073ad20318392659f4b`, ABI 1, and its Python adapter.

| Requirement | Supported wheel floor |
| --- | --- |
| App host | GIL-enabled CPython 3.11 or later, `cp311-abi3` |
| macOS | ARM64, macOS 13 or later |
| Linux | ARM64 and x86-64, glibc 2.36 or later |
| Windows | ARM64 and x86-64 |

Pip selects the platform wheel. The connector verifies the installed native
images against its package receipt before loading them.
[Python package on PyPI](https://pypi.org/project/coakka-runtime-python/) ·
[Compatibility matrix](https://github.com/phuong-tran/coakka-publish/blob/main/docs/coakka-runtime/reference/compatibility-matrix.md) ·
[Package and platform evidence](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/reference/runtime-package-platform-evidence.md)

## Upgrade or migrate

CoAkka uses `<product>-<language>` for recommended connector names.
`coakka-runtime-python` follows that convention. Choose either upgrade path.

### Keep the legacy name

```sh
python -m pip install --upgrade --only-binary=:all: coakka-v2-connector==3.3.2
```

Keep your `coakka_v2_connector` imports and update the version in your
requirements and lockfile.

### Switch to the recommended name

```sh
python -m pip install --upgrade --only-binary=:all: coakka-runtime-python==3.3.2
```

Replace the direct dependency in `requirements.txt` or `pyproject.toml` and
regenerate your lockfile. Keep your `coakka_v2_connector` imports. Pip still
installs `coakka-v2-connector==3.3.2` as the exact implementation dependency.
For a 2.x application, follow the API migration introduced in 3.0.0.
[Runtime changelog](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/CHANGELOG.md)

## Features and guides

### Request and reply

Use `RuntimeHost.start(...)` to own one active runtime per Python process.
`ConnectorOrchestrator.start(...)` remains available for existing callers.
Use `ask_payload(...)` and `register_payload_handler(...)` for bytes or
`ask_json(...)` for typed JSON. Use `submit_request_raw(...)`,
`submit_request_json(...)` or `submit_request_typed(...)` with
`terminal_events(...)` to consume responses and deadletters asynchronously.

Core owns request matching, deadlines and terminal status. Bytes-first handlers
run synchronously on the request reader. Keep them short to allow the reader to
serve other requests.
[Runtime integration guide](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/guides/runtime-integration-guide.md)

### Connection strategy

Omit `connection_strategy` at startup to use Core's persistent multiplexing.
Concurrent exchanges to the same endpoint can share one TCP connection.
In the default multiplexing mode, Core 3.3 supports up to **8 remote calls per
batch** and up to **16 in-flight exchanges per connection**. Read the accepted mode from
`runtime.tcp_connection_config().mode` and the remote batch limit from
`runtime.runtime_startup_config()["delivery"]["remoteBatchMaxCalls"]`.

To choose explicitly, pass a `RuntimeTcpConnectionStrategySpec` as
`connection_strategy` in `ConnectorStartSpec`. Use
`RuntimeTcpConnectionMode.MULTIPLEXING` for multiplexing or
`RuntimeTcpConnectionMode.PER_EXCHANGE` for one connection per exchange.
Create a new runtime to change the strategy after startup.
[Python transport configuration](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/reference/python-configuration.md) ·
[Connection strategy configuration](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/reference/connection-strategies.md)

### TCP and credentials

Core 3.3 supports TCP plaintext, TLS and mutual TLS. Startup defaults to
plaintext. Pass a `RuntimeTcpSecuritySpec` as `security` to choose a secure
mode and supply its credentials. Read the loaded capabilities with
`RuntimeHost.read_runtime_capabilities()` and the active mode with
`runtime.tcp_security_info()`.
[TLS and mutual TLS](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/reference/tls-and-mtls.md)

### Monitoring

Optional monitor collection is off by default. Set `enable_monitor=True` in
`ConnectorStartSpec` to enable it. Read the accepted setting at
`runtime.runtime_startup_config()["monitor"]["enabled"]` and collected data
through `runtime.monitor_snapshot()`. Basic health and pressure counters are
available with the default setting.
[Monitoring guide](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/operations/runtime-monitoring.md)

### Hot reload

Apply a newer route snapshot with `runtime.apply_snapshot(...)`. In TLS or
mutual TLS mode, reload credentials with `runtime.apply_tcp_security(...)`
under the configured reload policy. Check the returned status and active
configuration. Use a new runtime instance to change startup settings such as
the connection strategy, security mode or monitor enablement.
[Route snapshot generations](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/guides/runtime-cluster-routing.md#route-generation-discipline) ·
[Python credential reload](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/reference/python-configuration.md#tls-reload)

### Shutdown

Use `with RuntimeHost.start(...)` to close Runtime when the block exits.
For an explicitly managed host, call `close()` from its application owner.
Cancel or join application work that still uses resources you own.
[Troubleshooting](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/operations/troubleshooting.md)

## File Lane

Use `FileLane.open(...)` for bulk file transfer. Handle pause, cancellation
and completion using the lane's reported status. For replica delivery,
`FileLane.open_owned(...).prepare_receive_grant(...)` returns a grant
whose `to_send_spec(...)` method preserves the selected owner endpoint.
[File transfer guide](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/guides/runtime-file-transfer.md) ·
[Owner and replica grants](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/reference/runtime-lane-owner-grants.md)

## Stream Lane

Use `StreamLane.open(...)` for framed streams. With an owned lane,
`prepare_publish_grant(...)` returns a grant with a `to_subscribe_spec(...)`
helper. Callback buffers are borrowed for the callback. Copy bytes inside the
callback when the application needs to keep them.
[Streaming guide](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/guides/runtime-streaming.md)

## AI-Assisted Integration

Use the exact package version and a runnable example when generating Python
integration code. [AI-assisted integration guide](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/guides/ai-assisted-integration.md)

## Deployment

Run the connector inside your application. Choose a matching CPython interpreter and
platform wheel for each deployment.

| Environment | Where to start |
| --- | --- |
| LAN | Connect processes over TCP using reachable endpoints. Configure TLS or mutual TLS when the deployment requires authenticated peers. [Cluster routing](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/guides/runtime-cluster-routing.md) |
| Containers and Kubernetes | Set runtime identity and routes at startup. Use your service DNS and normal rollout process. [Container and Kubernetes guide](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/operations/containerized-runtime.md) |
| Bare-metal hosts and VMs | Install the package for the supported OS, architecture and app-host version. Follow the platform and lifecycle checks for your service. [Production readiness](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/operations/production-readiness.md) |
| Edge and IoT gateways | Use a compatible host, such as a Raspberry Pi 5 running Linux ARM64. Check the native package and app-host floors first. [Edge and IoT guide](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/previews/edge-iot-android.md#edge-linux-first) |

[Runtime operations guide](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/operations/README.md)

## Samples, benchmarks and support

- [CoAkka Samples](https://github.com/phuong-tran/coakka-samples) for runnable examples across the ecosystem.
- [CoAkka Publish](https://github.com/phuong-tran/coakka-publish) for releases, archives, checksums and platform evidence.
- [Runtime benchmarks](https://github.com/phuong-tran/coakka-publish/blob/main/coakka-runtime/benchmark/README.md) and the [benchmark quickstart](https://github.com/phuong-tran/coakka-publish/blob/main/docs/pi5-benchmark-quickstart.md).
- [CoAkka documentation](https://github.com/phuong-tran/coakka-samples/blob/main/docs/README.md) and the [AI-assisted integration guide](https://github.com/phuong-tran/coakka-samples/blob/main/docs/coakka-runtime/guides/ai-assisted-integration.md). Use the exact package and runnable sample when generating application code.

Email [support@coakka.io](mailto:support@coakka.io) for technical help and
[contact@coakka.io](mailto:contact@coakka.io) for general inquiries.
[Contact and support](https://github.com/phuong-tran/coakka-samples/blob/main/docs/common/contact-and-support.md)

## Sponsorship

Sponsorship helps maintain CoAkka's connector testing, documentation
and releases. [Sponsor CoAkka on GitHub](https://github.com/sponsors/phuong-tran).
For sponsorship and licensing inquiries, email
[contact@coakka.io](mailto:contact@coakka.io).

## License

**Free for application use, including commercial and production use.**

Connector source, types, samples and documentation use the
[Apache License 2.0](https://github.com/phuong-tran/coakka-samples/blob/main/LICENSE).
Bundled native files use the
[CoAkka Native Artifact License 1.2](https://github.com/phuong-tran/coakka-samples/blob/main/NATIVE-LICENSE.md).
The native terms permit ordinary application, commercial and SaaS use.
Offering CoAkka itself as a managed runtime or infrastructure requires a
separate agreement. Each package includes offline license and notice files.
[Package licensing](https://github.com/phuong-tran/coakka-samples/blob/main/docs/common/package-licensing.md)
