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

Uploaded Python 3

File details

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

File metadata

  • Download URL: asgi_cc-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 e215dc74123b59f7f14b691542a09d3b4ae4921b11cb598565bf545aabe9e05f
MD5 0054b6e4a826ae2136463d87fcc0d058
BLAKE2b-256 4790d20d1ca0a3036f718115f5602c09e6d111dbc8d0bd5856eb340c2173d765

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgi_cc-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: asgi_cc-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8c6b4ef30f56eb78de121100fbb06e922d46a24347e12c014154c6ff676d403f
MD5 8111736a529ce100f476ec568ea2682c
BLAKE2b-256 be94c3dd0cf3e97ab48573172d826bab339ea46944a065e1498d4822887c363a

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgi_cc-0.1.2-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