Skip to main content

Cranker v3 connector for ASGI applications

Project description

asgi-cc

asgi-cc is a Python Cranker connector for ASGI applications. It connects an ASGI app to a Cranker router over WebSocket and forwards HTTP traffic through the Cranker v3 protocol without adding a loopback HTTP hop inside the service process.

Features

  • ASGI-native request and response bridging
  • Cranker v3 (cranker_3.0) protocol support
  • FastAPI-compatible integration
  • DNS-based router discovery
  • Runtime app attach and detach support

Requirements

  • Python 3.11+

Installation

pip install asgi-cc

Basic Usage

Create the connector with the application and let the app lifecycle manage the connector:

import os

from fastapi import FastAPI

from asgi_cc import CrankerConnector, CrankerConnectorConfig

app = FastAPI()


@app.get("/hello")
async def hello() -> dict[str, str]:
    return {"message": "hello through cranker"}


connector = CrankerConnector(
    app,
    CrankerConnectorConfig(
        router_urls=[os.environ.get("CRANKER_ROUTER_URL", "wss://localhost:12001")],
        route="*",
        verify_ssl=False,
        component_name="my-service",
    ),
)

Keep using app as the ASGI server entrypoint. The connector registers itself on the app startup and shutdown hooks.

Middleware Usage

import os

from fastapi import FastAPI

from asgi_cc import CrankerConnector, CrankerConnectorConfig

app = FastAPI()

app.add_middleware(
    CrankerConnector,
    config=CrankerConnectorConfig(
        router_urls=[os.environ.get("CRANKER_ROUTER_URL", "wss://localhost:12001")],
        route="*",
        verify_ssl=False,
        component_name="my-service",
    ),
)

Runtime App Management

connector = CrankerConnector(config=config)

await connector.attach(app)
await connector.detach()

If the connector is started without an attached app, incoming requests receive 503 Service Unavailable until an app is attached.

Router Discovery

config = CrankerConnectorConfig(
    router_urls=["wss://router.example.org"],
    route="*",
    router_lookup_by_dns=True,
    router_update_interval_seconds=60,
)

When enabled, asgi-cc resolves router hostnames to IP addresses, opens registrations for the currently resolved routers, and periodically reconciles router registrations as DNS changes.

Project Links

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

asgi_cc-0.1.3.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

asgi_cc-0.1.3-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file asgi_cc-0.1.3.tar.gz.

File metadata

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

File hashes

Hashes for asgi_cc-0.1.3.tar.gz
Algorithm Hash digest
SHA256 51e8f760b267a1c7790feec48dcca33abf55f6a9c00f66d19f77bdbf906471fa
MD5 1b9c84df34f6da9b9ca118424aee1ff0
BLAKE2b-256 15a1d3cfe6e4ebebdc9e8fc2b0c1166eb56794aececf6588c8897181e9e8c5a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgi_cc-0.1.3.tar.gz:

Publisher: release.yml on wenLiangcan/asgi-cc

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

File details

Details for the file asgi_cc-0.1.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for asgi_cc-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fdfd1de2bb55e2a32a4ae93fa590787fcdfc7ddf4125129b40b38e43492457a6
MD5 833b7a27e20b8772fa9c012886d3d1be
BLAKE2b-256 6a0673bfb05bccf2f2e6f70142c1ff14fc549956fe8296c9a6cb911a51554c9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgi_cc-0.1.3-py3-none-any.whl:

Publisher: release.yml on wenLiangcan/asgi-cc

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