fastapi-lambda


Namefastapi-lambda JSON
Version 0.3.0 PyPI version JSON
download
home_pageNone
SummaryFastAPI fork optimized for AWS Lambda with minimal cold start overhead (inspired by FastAPI by SebastiΓ‘n RamΓ­rez)
upload_time2025-11-01 17:42:07
maintainerNone
docs_urlNone
authorTobias Silicani
requires_python>=3.10
licenseMIT
keywords fastapi lambda aws serverless api rest openapi pydantic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastAPI-Lambda

**Drop-in replacement for FastAPI** - Optimized for AWS Lambda with minimal cold start overhead and package size.

[![PyPI version](https://badge.fury.io/py/fastapi-lambda.svg)](https://pypi.org/project/fastapi-lambda/)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Downloads](https://static.pepy.tech/badge/fastapi-lambda)](https://pepy.tech/project/fastapi-lambda)
[![Development Status](https://img.shields.io/badge/status-alpha-red.svg)](https://github.com/tsilicani/fastapi-lambda)
[![Stability: Experimental](https://img.shields.io/badge/stability-experimental-orange.svg)](https://github.com/tsilicani/fastapi-lambda)
[![CI](https://github.com/tsilicani/fastapi-lambda/actions/workflows/ci.yml/badge.svg)](https://github.com/tsilicani/fastapi-lambda/actions/workflows/ci.yml)

---

## ⚠️ **EARLY DEVELOPMENT - NOT PRODUCTION READY**

> **WARNING:** This project is in **early alpha stage** and highly unstable. 
> 
> - 🚧 **Breaking changes** may occur without notice
> - πŸ› **Bugs and incomplete features** are expected
> - ❌ **NOT recommended for production use**
> - πŸ“ **API may change significantly** between versions
> 
> Use at your own risk! For production workloads, consider:
> - [FastAPI](https://github.com/fastapi/fastapi) (original) with [Mangum](https://github.com/jordaneremieff/mangum)
> - Wait for a stable 1.0.0 release of this project

---

## πŸš€ Why FastAPI-Lambda?

FastAPI-Lambda is a lightweight, Lambda-optimized framework that maintains FastAPI's intuitive API while removing unnecessary dependencies and features incompatible with serverless environments.

**Key Benefits:**
- ⚑ **<500ms cold starts** - No ASGI layer overhead
- πŸ”„ **Same FastAPI interfaces** - Minimal code changes required
- πŸ“¦ **Lightweight** - Pydantic v2.7+ only (single dependency)
- 🎯 **Lambda-native** - Direct API Gateway event handling
- βœ… **Sync & Async** - Supports both `def` and `async def` endpoints

## πŸ“Š Performance Comparison

| Metric | Standard FastAPI | FastAPI-Lambda |
|--------|-----------------|----------------|
| Cold Start | 1-2s (with ASGI) | <500ms (direct) |
| Package Size | ~5.8MB | ~3MB (48% reduction) |
| Dependencies | Starlette + extras | Pydantic only |
| Memory Overhead | ASGI + middleware | Minimal |

## πŸ“₯ Installation

```bash
pip install fastapi-lambda
```

## 🎯 Quick Start

```python
from fastapi_lambda import FastAPI

app = FastAPI()

# Both sync and async endpoints work!
@app.get("/")
def root():
    return {"message": "Hello from Lambda"}

@app.get("/async")
async def async_endpoint():
    return {"message": "Async works too!"}

# Lambda handler
from fastapi_lambda import create_lambda_handler
lambda_handler = create_lambda_handler(app)
```

## πŸ”Œ Deployment

### Lambda Function URL
```yaml
# serverless.yml
functions:
  api:
    handler: handler.lambda_handler
    url:
      cors: true
```

### API Gateway v1 (REST)
```yaml
functions:
  api:
    handler: handler.lambda_handler
    events:
      - http:
          path: "/"
          method: ANY
      - http:
          path: "{proxy+}"
          method: ANY
```

### API Gateway v2 (HTTP)
```yaml
functions:
  api:
    handler: handler.lambda_handler
    events:
      - httpApi:
          path: "/{proxy+}"
          method: "*"
```

## βœ… Supported Features

### HTTP REST API
- βœ… All methods: GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD
- βœ… Path/Query/Header parameters
- βœ… Request body validation
- βœ… Response models
- βœ… **Sync and async endpoints**

### Validation & Serialization
- βœ… **Pydantic v2 only** (Rust-powered performance)
- βœ… Type-based validation
- βœ… JSON encoding/decoding

### Dependency Injection
- βœ… `Depends()` with sync/async functions
- βœ… Generator-based cleanup (`yield`)
- βœ… Dependency caching
- βœ… Request/Response injection

### OpenAPI Schema
- βœ… Automatic OpenAPI 3.1.0 schema generation
- βœ… JSON endpoint at `/openapi.json`
- βœ… Complete request/response documentation
- πŸ“ Use external tools: Swagger Editor, Postman, Insomnia

### Security
- βœ… HTTP Bearer (JWT tokens)
- βœ… Custom security schemes

## ❌ Removed Features (Lambda Incompatible)

| Feature | Why Removed | Alternative |
|---------|-------------|-------------|
| WebSockets | Lambda doesn't support persistent connections | Use AWS API Gateway WebSocket API separately |
| Background Tasks | Lambda stops after response | Use SQS/EventBridge |
| File Uploads | Payload size limits | Use S3 pre-signed URLs |
| Streaming Responses | 6MB Lambda limit | Return URLs to S3 |
| Swagger UI/ReDoc | Reduce package size | Use external tools with `/openapi.json` |

## πŸ§ͺ Testing

### Unit Tests
```bash
# Run all tests
npm run test

# With coverage
npm run test:cov

# Watch mode
npm run test:watch
```

### E2E Tests
```bash
# Setup (deploy to AWS)
npm run test:e2e:setup

# Run E2E tests
npm run test:e2e
```

E2E tests automatically run against **all 3 deployment types**:
- Lambda Function URL
- API Gateway v1 (REST)
- API Gateway v2 (HTTP)

See [tests/e2e/README.md](tests/e2e/README.md) for details.

## πŸ“– Documentation

- [E2E Testing Guide](tests/e2e/README.md)
- [Architecture & Design](.claude/CLAUDE.md)

## 🀝 Contributing

Contributions are welcome! Please ensure:
- βœ… Tests pass (`npm run test`)
- βœ… Coverage >80% (`npm run test:cov`)
- βœ… No linting errors (`npm run lint`)
- βœ… Type checking passes (`npm run typecheck`)

## πŸ“œ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## πŸ™ Credits

This project is inspired by and derived from [FastAPI](https://github.com/fastapi/fastapi) by SebastiΓ‘n RamΓ­rez, licensed under the MIT License.

**FastAPI-Lambda** is an independent fork optimized specifically for AWS Lambda environments. It maintains API compatibility with FastAPI while removing ASGI dependencies and features incompatible with serverless execution.

### Key Differences from FastAPI

- **No ASGI layer** - Direct Lambda event handling
- **Minimal dependencies** - Pydantic v2.7+ only
- **Lambda-optimized** - <500ms cold starts
- **Smaller package** - ~48% size reduction

For traditional web applications or features like WebSockets, use the original [FastAPI](https://github.com/fastapi/fastapi).

## πŸ”— Related Projects

- [FastAPI](https://github.com/fastapi/fastapi) - Original FastAPI framework
- [Starlette](https://github.com/encode/starlette) - ASGI framework (removed in this fork)
- [Pydantic](https://github.com/pydantic/pydantic) - Data validation
- [Mangum](https://github.com/jordaneremieff/mangum) - ASGI adapter for AWS Lambda (alternative approach)

## πŸ“§ Support

- **Issues**: [GitHub Issues](https://github.com/tsilicani/fastapi-lambda/issues)
- **Discussions**: [GitHub Discussions](https://github.com/tsilicani/fastapi-lambda/discussions)

---

Made with ❀️ for the serverless community


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fastapi-lambda",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "fastapi, lambda, aws, serverless, api, rest, openapi, pydantic",
    "author": "Tobias Silicani",
    "author_email": "tobias@example.com",
    "download_url": "https://files.pythonhosted.org/packages/d3/c2/4d0221beb93b83f88775f2fdad02baf7a18df7024ab6e67a7717a8f16752/fastapi_lambda-0.3.0.tar.gz",
    "platform": null,
    "description": "# FastAPI-Lambda\n\n**Drop-in replacement for FastAPI** - Optimized for AWS Lambda with minimal cold start overhead and package size.\n\n[![PyPI version](https://badge.fury.io/py/fastapi-lambda.svg)](https://pypi.org/project/fastapi-lambda/)\n[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Downloads](https://static.pepy.tech/badge/fastapi-lambda)](https://pepy.tech/project/fastapi-lambda)\n[![Development Status](https://img.shields.io/badge/status-alpha-red.svg)](https://github.com/tsilicani/fastapi-lambda)\n[![Stability: Experimental](https://img.shields.io/badge/stability-experimental-orange.svg)](https://github.com/tsilicani/fastapi-lambda)\n[![CI](https://github.com/tsilicani/fastapi-lambda/actions/workflows/ci.yml/badge.svg)](https://github.com/tsilicani/fastapi-lambda/actions/workflows/ci.yml)\n\n---\n\n## \u26a0\ufe0f **EARLY DEVELOPMENT - NOT PRODUCTION READY**\n\n> **WARNING:** This project is in **early alpha stage** and highly unstable. \n> \n> - \ud83d\udea7 **Breaking changes** may occur without notice\n> - \ud83d\udc1b **Bugs and incomplete features** are expected\n> - \u274c **NOT recommended for production use**\n> - \ud83d\udcdd **API may change significantly** between versions\n> \n> Use at your own risk! For production workloads, consider:\n> - [FastAPI](https://github.com/fastapi/fastapi) (original) with [Mangum](https://github.com/jordaneremieff/mangum)\n> - Wait for a stable 1.0.0 release of this project\n\n---\n\n## \ud83d\ude80 Why FastAPI-Lambda?\n\nFastAPI-Lambda is a lightweight, Lambda-optimized framework that maintains FastAPI's intuitive API while removing unnecessary dependencies and features incompatible with serverless environments.\n\n**Key Benefits:**\n- \u26a1 **<500ms cold starts** - No ASGI layer overhead\n- \ud83d\udd04 **Same FastAPI interfaces** - Minimal code changes required\n- \ud83d\udce6 **Lightweight** - Pydantic v2.7+ only (single dependency)\n- \ud83c\udfaf **Lambda-native** - Direct API Gateway event handling\n- \u2705 **Sync & Async** - Supports both `def` and `async def` endpoints\n\n## \ud83d\udcca Performance Comparison\n\n| Metric | Standard FastAPI | FastAPI-Lambda |\n|--------|-----------------|----------------|\n| Cold Start | 1-2s (with ASGI) | <500ms (direct) |\n| Package Size | ~5.8MB | ~3MB (48% reduction) |\n| Dependencies | Starlette + extras | Pydantic only |\n| Memory Overhead | ASGI + middleware | Minimal |\n\n## \ud83d\udce5 Installation\n\n```bash\npip install fastapi-lambda\n```\n\n## \ud83c\udfaf Quick Start\n\n```python\nfrom fastapi_lambda import FastAPI\n\napp = FastAPI()\n\n# Both sync and async endpoints work!\n@app.get(\"/\")\ndef root():\n    return {\"message\": \"Hello from Lambda\"}\n\n@app.get(\"/async\")\nasync def async_endpoint():\n    return {\"message\": \"Async works too!\"}\n\n# Lambda handler\nfrom fastapi_lambda import create_lambda_handler\nlambda_handler = create_lambda_handler(app)\n```\n\n## \ud83d\udd0c Deployment\n\n### Lambda Function URL\n```yaml\n# serverless.yml\nfunctions:\n  api:\n    handler: handler.lambda_handler\n    url:\n      cors: true\n```\n\n### API Gateway v1 (REST)\n```yaml\nfunctions:\n  api:\n    handler: handler.lambda_handler\n    events:\n      - http:\n          path: \"/\"\n          method: ANY\n      - http:\n          path: \"{proxy+}\"\n          method: ANY\n```\n\n### API Gateway v2 (HTTP)\n```yaml\nfunctions:\n  api:\n    handler: handler.lambda_handler\n    events:\n      - httpApi:\n          path: \"/{proxy+}\"\n          method: \"*\"\n```\n\n## \u2705 Supported Features\n\n### HTTP REST API\n- \u2705 All methods: GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD\n- \u2705 Path/Query/Header parameters\n- \u2705 Request body validation\n- \u2705 Response models\n- \u2705 **Sync and async endpoints**\n\n### Validation & Serialization\n- \u2705 **Pydantic v2 only** (Rust-powered performance)\n- \u2705 Type-based validation\n- \u2705 JSON encoding/decoding\n\n### Dependency Injection\n- \u2705 `Depends()` with sync/async functions\n- \u2705 Generator-based cleanup (`yield`)\n- \u2705 Dependency caching\n- \u2705 Request/Response injection\n\n### OpenAPI Schema\n- \u2705 Automatic OpenAPI 3.1.0 schema generation\n- \u2705 JSON endpoint at `/openapi.json`\n- \u2705 Complete request/response documentation\n- \ud83d\udcdd Use external tools: Swagger Editor, Postman, Insomnia\n\n### Security\n- \u2705 HTTP Bearer (JWT tokens)\n- \u2705 Custom security schemes\n\n## \u274c Removed Features (Lambda Incompatible)\n\n| Feature | Why Removed | Alternative |\n|---------|-------------|-------------|\n| WebSockets | Lambda doesn't support persistent connections | Use AWS API Gateway WebSocket API separately |\n| Background Tasks | Lambda stops after response | Use SQS/EventBridge |\n| File Uploads | Payload size limits | Use S3 pre-signed URLs |\n| Streaming Responses | 6MB Lambda limit | Return URLs to S3 |\n| Swagger UI/ReDoc | Reduce package size | Use external tools with `/openapi.json` |\n\n## \ud83e\uddea Testing\n\n### Unit Tests\n```bash\n# Run all tests\nnpm run test\n\n# With coverage\nnpm run test:cov\n\n# Watch mode\nnpm run test:watch\n```\n\n### E2E Tests\n```bash\n# Setup (deploy to AWS)\nnpm run test:e2e:setup\n\n# Run E2E tests\nnpm run test:e2e\n```\n\nE2E tests automatically run against **all 3 deployment types**:\n- Lambda Function URL\n- API Gateway v1 (REST)\n- API Gateway v2 (HTTP)\n\nSee [tests/e2e/README.md](tests/e2e/README.md) for details.\n\n## \ud83d\udcd6 Documentation\n\n- [E2E Testing Guide](tests/e2e/README.md)\n- [Architecture & Design](.claude/CLAUDE.md)\n\n## \ud83e\udd1d Contributing\n\nContributions are welcome! Please ensure:\n- \u2705 Tests pass (`npm run test`)\n- \u2705 Coverage >80% (`npm run test:cov`)\n- \u2705 No linting errors (`npm run lint`)\n- \u2705 Type checking passes (`npm run typecheck`)\n\n## \ud83d\udcdc License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## \ud83d\ude4f Credits\n\nThis project is inspired by and derived from [FastAPI](https://github.com/fastapi/fastapi) by Sebasti\u00e1n Ram\u00edrez, licensed under the MIT License.\n\n**FastAPI-Lambda** is an independent fork optimized specifically for AWS Lambda environments. It maintains API compatibility with FastAPI while removing ASGI dependencies and features incompatible with serverless execution.\n\n### Key Differences from FastAPI\n\n- **No ASGI layer** - Direct Lambda event handling\n- **Minimal dependencies** - Pydantic v2.7+ only\n- **Lambda-optimized** - <500ms cold starts\n- **Smaller package** - ~48% size reduction\n\nFor traditional web applications or features like WebSockets, use the original [FastAPI](https://github.com/fastapi/fastapi).\n\n## \ud83d\udd17 Related Projects\n\n- [FastAPI](https://github.com/fastapi/fastapi) - Original FastAPI framework\n- [Starlette](https://github.com/encode/starlette) - ASGI framework (removed in this fork)\n- [Pydantic](https://github.com/pydantic/pydantic) - Data validation\n- [Mangum](https://github.com/jordaneremieff/mangum) - ASGI adapter for AWS Lambda (alternative approach)\n\n## \ud83d\udce7 Support\n\n- **Issues**: [GitHub Issues](https://github.com/tsilicani/fastapi-lambda/issues)\n- **Discussions**: [GitHub Discussions](https://github.com/tsilicani/fastapi-lambda/discussions)\n\n---\n\nMade with \u2764\ufe0f for the serverless community\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "FastAPI fork optimized for AWS Lambda with minimal cold start overhead (inspired by FastAPI by Sebasti\u00e1n Ram\u00edrez)",
    "version": "0.3.0",
    "project_urls": {
        "Documentation": "https://github.com/tsilicani/fastapi-lambda#readme",
        "Homepage": "https://github.com/tsilicani/fastapi-lambda",
        "Issues": "https://github.com/tsilicani/fastapi-lambda/issues",
        "Repository": "https://github.com/tsilicani/fastapi-lambda"
    },
    "split_keywords": [
        "fastapi",
        " lambda",
        " aws",
        " serverless",
        " api",
        " rest",
        " openapi",
        " pydantic"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "93539bfd839194afd15a1fa8c655e72261248c0986874657e0dc8700d312490f",
                "md5": "831437ea04d5dfc989649fff1f4e449f",
                "sha256": "6c889fee1a1314c5f1529a397f8b36a384e0c88e21552f128d1126cc258e3d60"
            },
            "downloads": -1,
            "filename": "fastapi_lambda-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "831437ea04d5dfc989649fff1f4e449f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 47573,
            "upload_time": "2025-11-01T17:42:05",
            "upload_time_iso_8601": "2025-11-01T17:42:05.656564Z",
            "url": "https://files.pythonhosted.org/packages/93/53/9bfd839194afd15a1fa8c655e72261248c0986874657e0dc8700d312490f/fastapi_lambda-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d3c24d0221beb93b83f88775f2fdad02baf7a18df7024ab6e67a7717a8f16752",
                "md5": "555e6f7584966527914a37522bb8151a",
                "sha256": "ffd26d3087fc2f540a28578961cd2148abf3a97d465b514877201506f279a67f"
            },
            "downloads": -1,
            "filename": "fastapi_lambda-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "555e6f7584966527914a37522bb8151a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 40061,
            "upload_time": "2025-11-01T17:42:07",
            "upload_time_iso_8601": "2025-11-01T17:42:07.611627Z",
            "url": "https://files.pythonhosted.org/packages/d3/c2/4d0221beb93b83f88775f2fdad02baf7a18df7024ab6e67a7717a8f16752/fastapi_lambda-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-11-01 17:42:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tsilicani",
    "github_project": "fastapi-lambda#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fastapi-lambda"
}
        
Elapsed time: 2.33009s