Skip to main content

CoAkka HTTP Runtime for Python

CoAkka

CoAkka HTTP Runtime is an embeddable HTTP server and client for Python. Use Python handlers to serve HTTP APIs, stream responses, handle WebSockets or call upstream services. The wheel includes the shared native HTTP core for your platform.

The CoAkka ecosystem provides polyglot tools for distributed applications, HTTP services and logging. CoAkka HTTP Runtime is the HTTP product and can be adopted independently.

CoAkka ecosystem · Raspberry Pi 5 benchmarks · GitHub Sponsors · Ko-fi

Read the version

In 2.3.1, 2.3 is the Core generation and the final 1 is this connector's revision on that generation. The revision starts at 1 for each connector. A connector-only update can advance to 2.3.2 while using the same native SDK and checksums. This release uses Core SDK 2.3.0 with C ABI 10. Version and SDK compatibility

Install 2.3.1

Run these commands from your application directory with CPython 3.11 or newer.

On macOS or Linux:

python3 -m venv .venv
.venv/bin/python -m pip install coakka-http-runtime-python==2.3.1

On Windows in PowerShell:

py -3 -m venv .venv
.\.venv\Scripts\python.exe -m pip install coakka-http-runtime-python==2.3.1

Install coakka-http-runtime-python with pip and import coakka_http in your application.

First request

Save this example as server.py.

from coakka_http import Builder, Request, Response


def echo(request: Request) -> Response:
    return Response(status=201, body=request.body)


def main() -> None:
    service = Builder().listen("127.0.0.1", 8080).post("/echo", echo).start()
    with service:
        print(f"Listening on http://127.0.0.1:{service.port}")
        input("Press Enter to stop. ")


if __name__ == "__main__":
    main()

Run .venv/bin/python server.py on macOS or Linux, or .\.venv\Scripts\python.exe server.py on Windows. From a second terminal, send a request with the following command.

curl -i --data "hello" http://127.0.0.1:8080/echo

In Windows PowerShell, use curl.exe. The server returns HTTP 201 with hello in the response body. Press Enter in the server terminal to shut it down. The service context manager closes the runtime when the block exits.

Requirements

Platform Architecture Requirement
macOS ARM64 macOS 11 or newer
Linux x86-64 and ARM64 glibc 2.28 or newer
Windows x64 and ARM64 CPython matching the wheel architecture

If pip cannot find a matching wheel, run python -VV and python -c "import platform; print(platform.machine())" with the interpreter you plan to use. Install and run the package with that interpreter.

Choose an HTTP version

Builder.listen() in the first example starts a plain HTTP/1.1 listener. For HTTP/2 or HTTP/3, generate the local TLS files and pass a Listener to the builder instead. For example:

from coakka_http import Builder, Listener, ListenerProtocol, TransportSecurity

builder = Builder().listener(
    Listener(
        port=8443,
        protocol=ListenerProtocol.HTTP_2,
        security=TransportSecurity.TLS,
        credential_id="local-example",
        credential_generation=1,
        certificate_chain_file="http-test-tls/server.pem",
        private_key_file="http-test-tls/server.key",
    )
)

Register your routes on builder, then call start(). Use ListenerProtocol.HTTP_3 to serve HTTP/3 over UDP. The complete Python sample runs all 3 modes separately.

Run HTTP/1.1, HTTP/2 and HTTP/3 on one port

Use MultiProtocolListener with Builder.multi_protocol_listener() to serve one buffered route over all 3 HTTP versions on the same TLS port. TCP carries HTTP/1.1 and HTTP/2. UDP carries HTTP/3 on that port.

Generate the local TLS files linked above and place http-test-tls in your application directory. Save this example as multi_server.py.

from coakka_http import Builder, MultiProtocolListener, Request, Response


def hello(_request: Request) -> Response:
    return Response.text("hello")


def main() -> None:
    listener = MultiProtocolListener(
        certificate_chain_file="http-test-tls/server.pem",
        private_key_file="http-test-tls/server.key",
        credential_id="local-example",
        bind_address="127.0.0.1",
        port=8443,
    )
    builder = Builder().multi_protocol_listener(listener).get("/hello", hello)
    with builder.start() as service:
        info = service.multi_protocol_listener_info()
        print(f"Listening on https://127.0.0.1:{info.port}", flush=True)
        input("Press Enter to stop. ")


if __name__ == "__main__":
    main()

Run .venv/bin/python multi_server.py on macOS or Linux, or .\.venv\Scripts\python.exe multi_server.py in PowerShell. Leave the server running and run these commands in another terminal. On Windows, use curl.exe.

curl --http1.1 --noproxy '*' --cacert http-test-tls/ca.pem --fail --max-time 10 -sS -w "\n%{http_code} %{http_version}\n" https://127.0.0.1:8443/hello
curl --http2 --noproxy '*' --cacert http-test-tls/ca.pem --fail --max-time 10 -sS -w "\n%{http_code} %{http_version}\n" https://127.0.0.1:8443/hello
curl --http3-only --noproxy '*' --cacert http-test-tls/ca.pem --fail --max-time 10 -sS -w "\n%{http_code} %{http_version}\n" https://127.0.0.1:8443/hello

The 3 requests return the same body and show the HTTP version used.

hello
200 1.1
hello
200 2
hello
200 3

curl --version should list HTTP2 and HTTP3 under features. --http3-only requires HTTP/3 and reports an error if the connection cannot use it. Press Enter in the server terminal to close the listener.

HTTP/1.1 · HTTP/2 · HTTP/3

Outbound requests

Keep the first server running. Save this example as client.py and run it with the same virtual environment's Python. It sends a request to the configured loopback endpoint and prints 201 hello.

from coakka_http import (
    Builder,
    OutboundEndpoint,
    OutboundReason,
    OutboundRequest,
    OutboundTarget,
)


def main() -> None:
    endpoint = OutboundEndpoint(
        node_id="local",
        connect_host="127.0.0.1",
        connect_port=8080,
        http_authority="127.0.0.1:8080",
    )
    target = OutboundTarget(name="echo", generation=1, endpoints=(endpoint,))

    with Builder().outbound_target(target).start() as service:
        call = service.outbound_submit(
            OutboundRequest("echo", "POST", "/echo", body=b"hello", timeout_ms=3000)
        )
        result = service.take_outbound(5000)
        if result is None:
            raise TimeoutError("No outbound result within five seconds")
        if result.call != call or result.reason is not OutboundReason.RESPONSE:
            raise RuntimeError(f"Outbound request ended with {result.reason.name}")
        print(result.response_status, result.response_body.decode("utf-8"))


if __name__ == "__main__":
    main()

connect_host selects the connection destination and http_authority sets the HTTP authority. For TLS, configure the peer identity and trust for the endpoint. A received HTTP error still arrives as a response with its HTTP status. Use the terminal reason to distinguish transport and lifecycle outcomes.

API reference

Builder creates one service. The service supports buffered and streamed requests, streaming responses and trailers, SSE, WebSockets, static files, outbound targets, generation-checked route updates, TLS and mTLS, and bounded monitoring.

service.routes returns the runtime's route generation and binding revisions. Use effective_limits() and runtime_info() to inspect the configuration accepted by the runtime. Use Builder.compression(Compression(CompressionMode.GZIP)) to enable buffered response compression.

I/O backend

The service uses the platform's default I/O backend. On Linux, applications can request io_uring explicitly.

from coakka_http import Builder, IoBackend, Response

service = (
    Builder()
    .io_backend(IoBackend.IO_URING)
    .get("/health", lambda _request: Response())
    .start()
)
try:
    info = service.runtime_info()
    print(info.io_uring_requested, info.io_uring_effective, info.fallback_reason)
finally:
    service.close()

The native runtime checks availability and uses the platform default when the request cannot be applied. Read io_uring_effective to see the backend in use and fallback_reason for the outcome of the request.

Lower-level API

Runtime accepts one immutable RuntimeConfig and returns copied events.

from coakka_http import EventKind, Response, Route, Runtime, RuntimeConfig

configuration = RuntimeConfig(routes=(Route(41, "POST", "/items/{id}", 101),))
with Runtime(configuration) as runtime:
    runtime.start()
    event = runtime.take_event(5_000)
    if event is not None and event.kind is EventKind.REQUEST:
        runtime.respond(event.exchange, Response(status=202, body=b"accepted"))

Each blocking inbound, WebSocket, outbound, and monitor lane allows one reader. All native views are copied during the call; no borrowed pointer escapes into Python. Failures are NativeError values with a stable numeric status and a bounded diagnostic.

Ownership and bounds

Worker count, queued request count, retained bytes, stream items, handler bindings, active exchanges, monitor pages, and shutdown time are finite. Returning a streaming response gives one callback-scoped writer to its producer. Pressure waits for native recovery credit and retries only the exact rejected item.

Service.close() stops admission, wakes readers, joins connector workers, and destroys native ownership only when no Python code can still reach it. If a handler exceeds the deadline, close raises and retains the owner for a safe retry. The operation is serialized and idempotent.

Monitoring is disabled by default. Enabling it reserves fixed storage during construction. Signals are hints; callers pull immutable snapshots. Monitoring pressure cannot block request handling or change an exchange result.

HTTP Runtime documentation

Metadata

Release files for coakka-http-runtime-python 2.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for coakka-http-runtime-python 2.3.1
File Actions
coakka_http_runtime_python-2.3.1-cp311-abi3-win_arm64.whl CPython 3.11 abi3 Windows ARM64 Details for coakka_http_runtime_python-2.3.1-cp311-abi3-win_arm64.whl
coakka_http_runtime_python-2.3.1-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for coakka_http_runtime_python-2.3.1-cp311-abi3-win_amd64.whl
coakka_http_runtime_python-2.3.1-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details for coakka_http_runtime_python-2.3.1-cp311-abi3-manylinux_2_28_x86_64.whl
coakka_http_runtime_python-2.3.1-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details for coakka_http_runtime_python-2.3.1-cp311-abi3-manylinux_2_28_aarch64.whl
coakka_http_runtime_python-2.3.1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for coakka_http_runtime_python-2.3.1-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 19.6 MB

Release files / coakka_http_runtime_python-2.3.1-cp311-abi3-win_arm64.whl

Download URL coakka_http_runtime_python-2.3.1-cp311-abi3-win_arm64.whl
Size 3.2 MB
Tags CPython 3.11 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
5985aa2003a8f05b27980b94ded535c879466de745e916f8b7cb83332e9aa656
BLAKE2b-256 checksum
How to use checksums
a45daa0d4944200eb622c8c0936d054adf7dfaedee958e7327ec8399b583cca7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release files / coakka_http_runtime_python-2.3.1-cp311-abi3-win_amd64.whl

Download URL coakka_http_runtime_python-2.3.1-cp311-abi3-win_amd64.whl
Size 3.9 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
053313507f934625c8552bba58899cd35d9d131847a2a61a93cc8ecc5a4e0844
BLAKE2b-256 checksum
How to use checksums
9cf6018224e3e1fda804d30f056c1559ccd3cff04f197a541edbfadbcc512c9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release files / coakka_http_runtime_python-2.3.1-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL coakka_http_runtime_python-2.3.1-cp311-abi3-manylinux_2_28_x86_64.whl
Size 4.4 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
52d7b4816c0e646538b9614b11f9d940576d735e7f4f2ba0d71ca87669e49f89
BLAKE2b-256 checksum
How to use checksums
1ba09152d40160dbc7e4eb02ebc569a0fcdd96b2a3e38be8bb9ea2a591cf94e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release files / coakka_http_runtime_python-2.3.1-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL coakka_http_runtime_python-2.3.1-cp311-abi3-manylinux_2_28_aarch64.whl
Size 4.6 MB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
5a0e7ef22fd61925294040969e5a173d47912e36784d6e302466125dac998232
BLAKE2b-256 checksum
How to use checksums
dffcfa007d07df359b8c27d1097e668d31d07154285befe48eab59dd1ca7fb0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release files / coakka_http_runtime_python-2.3.1-cp311-abi3-macosx_11_0_arm64.whl

Download URL coakka_http_runtime_python-2.3.1-cp311-abi3-macosx_11_0_arm64.whl
Size 3.6 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d70e5ea01ce9437dc8f2a5777981830797e13b9a8599e99353fdd96d86cdaa81
BLAKE2b-256 checksum
How to use checksums
cc119569463284d220e9fc03164dc730176f45c69ebc9d5e0bc9e14b19ca5ab2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Security for coakka-http-runtime-python 2.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page