Skip to main content

ngrok-fastapi

Bring ngrok Traffic Policy, pooling, and binding config to FastAPI — via FastAPI's own lifespan hook, with one call:

from fastapi import FastAPI
import ngrok_fastapi

app = FastAPI()
ngrok_fastapi.attach(app, ngrok_fastapi.Config(port=8000))

What it is

A small FastAPI-native ngrok library. attach()/attach_many() wrap an app's existing lifespan context manager so an ngrok tunnel opens when the app starts and closes when it stops.

Setup

  1. Sign up at ngrok.com and grab an authtoken from the dashboard.
  2. Set it as an env var: NGROK_AUTHTOKEN=your_token_here
  3. pip install ngrok-fastapi and call attach() — see examples/basic.py.

Config

ngrok_fastapi.attach(app, ngrok_fastapi.Config(
    port=8000,
    url="your-reserved-domain.ngrok.app",  # None = account's default dev domain
    pooling=False,
    traffic_policy="""
on_http_request:
  - actions:
      - type: basic-auth
        config:
          credentials:
            - "user:password123"
""",
    binding=None,  # ngrok_fastapi.Binding.INTERNAL, etc.
))

See examples/with_config.py for a working example.

Field Type Description
port int Local port this endpoint forwards to.
url Optional[str] Reserved domain for this endpoint. None falls back to the account's default dev domain.
pooling bool Opt in to ngrok endpoint pooling — required if another endpoint on the same session would otherwise collide on the same domain. See Collisions.
traffic_policy Optional[str] A raw ngrok Traffic Policy document (YAML or JSON) — the mechanism for auth, IP restrictions, header manipulation, webhook verification, and more.
binding Optional[Binding] PUBLIC / INTERNAL / KUBERNETES ingress configuration. Not part of Traffic Policy (checked ngrok's actions reference directly — no equivalent exists), so it stays a standalone field. INTERNAL requires url to end in .internal, enforced by ngrok itself (ERR_NGROK_9029 if it doesn't).

Multiple endpoints

attach_many(app, configs) opens one endpoint per Config, all on a single session, and ties all of them to the same app's lifespan. attach(app, config) is just attach_many(app, [config]).

ngrok_fastapi.attach_many(app, [
    ngrok_fastapi.Config(port=8000, url="app.mycompany.ngrok.app"),
    ngrok_fastapi.Config(port=8001, url="api.mycompany.ngrok.app"),
])

Development

python3 -m venv venv && source venv/bin/activate
pip install -e ".[dev]"
pytest
python examples/basic.py

See DESIGN.md for the design rationale and everything confirmed empirically along the way.

License

MIT OR Apache-2.0

Metadata

Release files for ngrok-fastapi 0.2.0

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

Source distribution (sdist)

Source distribution for ngrok-fastapi 0.2.0
File Size Uploaded Provenance Actions
ngrok_fastapi-0.2.0.tar.gz 10.0 kB With provenance Details for ngrok_fastapi-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ngrok-fastapi 0.2.0
File Interpreter ABI Platform Actions
ngrok_fastapi-0.2.0-py3-none-any.whl Python 3 none any Details for ngrok_fastapi-0.2.0-py3-none-any.whl

Total release size: 20.6 kB

Release files / ngrok_fastapi-0.2.0.tar.gz

Download URL ngrok_fastapi-0.2.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
803a7c82a12fd6d82a3615ef680c9357741da6b8ac0bca89c05383282995f3b6
BLAKE2b-256 checksum
How to use checksums
94baf36d23b713dc2e36a2ec868e5dd959a3af83b67373c895e2ef9a9af13527
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / ngrok_fastapi-0.2.0-py3-none-any.whl

Download URL ngrok_fastapi-0.2.0-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52c290ecc915a853417b834879a0d8bddd44348da6ab01385cf30b753773fb12
BLAKE2b-256 checksum
How to use checksums
4a211f096f76517cf11a209ed1169b2673842fd2d0f66ad3320506a2855b1565
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for ngrok-fastapi 0.2.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ngrok_fastapi-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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