Run FastAPI apps inside Firebase Functions with full HTTP forwarding
Project description
🔥 firebase-fastapi-wrapper
A lightweight, production-ready adapter that lets you run any FastAPI (or ASGI) application inside Firebase Cloud Functions — with full support for all HTTP methods, CORS, timeouts, and structured error handling.
✨ Features
| Feature | Details |
|---|---|
| 🔄 Full HTTP forwarding | GET, POST, PUT, PATCH, DELETE — all forwarded correctly |
| 🔒 CORS support | Built-in cors_origins allow-list |
| ⏱️ Timeout protection | Configurable per-request timeout |
| 🐛 Structured errors | JSON error responses with unique request_id for tracing |
| 🏷️ Typed | Full type annotations + PEP 561 py.typed marker |
| 🐍 Python 3.10 → 3.12 | Tested on all active Python versions |
| 🌐 Multi-server | Works in Firebase Functions and locally with Uvicorn |
🚀 Installation
# pip
pip install firebase-fastapi-wrapper
# uv
uv add firebase-fastapi-wrapper
# Poetry
poetry add firebase-fastapi-wrapper
🧩 Quickstart (Firebase Functions)
# functions/main.py
from fastapi import FastAPI
from firebase_functions import https_fn
from firebase_fastapi_wrapper import FastAPIWrapper
app = FastAPI()
@app.get("/hello")
def hello():
return {"message": "Hello from FastAPI inside Firebase!"}
@app.get("/users/{user_id}")
def get_user(user_id: str):
return {"user_id": user_id}
# Wrap once at module level
firebase_handler = FastAPIWrapper(app)
@https_fn.on_request()
def handle_request(req: https_fn.Request) -> https_fn.Response:
return firebase_handler(req)
requirements.txt (Firebase Functions needs this):
firebase-fastapi-wrapper>=0.2.0
🌐 Local Development (Uvicorn / any server)
You don't need Firebase to develop and test your app. Run it directly with Uvicorn — the same FastAPI app works on any ASGI server:
# local_server.py
import uvicorn
from main import app # import your FastAPI app
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000, reload=True)
pip install uvicorn
python local_server.py
# → http://localhost:8000/hello
# → http://localhost:8000/docs (Swagger UI)
Tip: Use an environment variable to switch between Firebase and local mode:
import os if os.getenv("RUNNING_IN_FIREBASE"): firebase_handler = FastAPIWrapper(app) else: import uvicorn uvicorn.run(app, port=8000)
⚙️ Advanced Configuration
firebase_handler = FastAPIWrapper(
app,
# Allow specific origins to make cross-origin requests
cors_origins=["https://myapp.web.app", "https://example.com"],
# Request timeout in seconds (default: 30)
timeout=60,
# Hide exception details in production (default: True)
error_include_detail=False,
# Raise exceptions instead of returning 500 — useful in tests
raise_on_error=False,
)
CORS with wildcard
firebase_handler = FastAPIWrapper(app, cors_origins=["*"])
🚦 Error Handling
All unhandled exceptions are caught and returned as structured JSON:
{
"error": "Internal Server Error",
"request_id": "550e8400-e29b-41d4-a716-446655440000"
}
Set error_include_detail=True during development to also see the exception message:
{
"error": "Internal Server Error",
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"detail": "division by zero"
}
🧪 Running Tests
# Install dev dependencies
uv sync --extra dev
# Run the full test suite
uv run pytest tests/ -v
# With coverage report
uv run pytest tests/ -v --cov=firebase_fastapi_wrapper --cov-report=term-missing
🤝 Contributing
See CONTRIBUTING.md for setup instructions, commit conventions, and how to open a PR.
📄 License
MIT © Mohamed Emam
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file firebase_fastapi_wrapper-0.2.0.tar.gz.
File metadata
- Download URL: firebase_fastapi_wrapper-0.2.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
402af36b4bf5d797de393917c78a15039665665501d8e04f0c5524f088e8af50
|
|
| MD5 |
73fdbfeb4252466456f09cc8ac05f225
|
|
| BLAKE2b-256 |
5df178e13afa8c081640bc4d31e355a4c687b4a6b78a8c0bfead16c697225106
|
Provenance
The following attestation bundles were made for firebase_fastapi_wrapper-0.2.0.tar.gz:
Publisher:
publish.yml on mohamed-em2m/firebase-fastapi-wrapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
firebase_fastapi_wrapper-0.2.0.tar.gz -
Subject digest:
402af36b4bf5d797de393917c78a15039665665501d8e04f0c5524f088e8af50 - Sigstore transparency entry: 1355509764
- Sigstore integration time:
-
Permalink:
mohamed-em2m/firebase-fastapi-wrapper@8bbadd3d9a1e16b295d4e96edde5489d2ed93612 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mohamed-em2m
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8bbadd3d9a1e16b295d4e96edde5489d2ed93612 -
Trigger Event:
release
-
Statement type:
File details
Details for the file firebase_fastapi_wrapper-0.2.0-py3-none-any.whl.
File metadata
- Download URL: firebase_fastapi_wrapper-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1dcd0cffda2ecd76b91ac0fdf2e74e3ec711445ec97ccf743e088be179dc9ab
|
|
| MD5 |
ccc656b8c03856a7b5389e686d5b70d2
|
|
| BLAKE2b-256 |
8fc69bfc20255305f2159b75768714ce4cff6e969fd5e4a2c4c65324ae23f76d
|
Provenance
The following attestation bundles were made for firebase_fastapi_wrapper-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on mohamed-em2m/firebase-fastapi-wrapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
firebase_fastapi_wrapper-0.2.0-py3-none-any.whl -
Subject digest:
d1dcd0cffda2ecd76b91ac0fdf2e74e3ec711445ec97ccf743e088be179dc9ab - Sigstore transparency entry: 1355509770
- Sigstore integration time:
-
Permalink:
mohamed-em2m/firebase-fastapi-wrapper@8bbadd3d9a1e16b295d4e96edde5489d2ed93612 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mohamed-em2m
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8bbadd3d9a1e16b295d4e96edde5489d2ed93612 -
Trigger Event:
release
-
Statement type: