Skip to main content

モダンな AWS Lambda 用 API フレームワーク

Project description

lambapi

モダンな AWS Lambda 用 API フレームワーク

Python Version License

AWS Lambda で直感的でモダンな API を構築できる軽量フレームワーク。パスパラメータとクエリパラメータの自動注入、型変換、CORS サポートを標準提供。

✨ 主な特徴

  • 🚀 直感的な記法 - デコレータベースのシンプルなルート定義
  • 📋 自動パラメータ注入 - パス・クエリパラメータを関数引数として直接受け取り
  • 🔄 型自動変換 - intfloatboolstr の自動型変換
  • 🌐 CORS サポート - プリフライトリクエストの自動処理
  • 🛡️ 構造化エラーハンドリング - 本番運用に適した統一エラーレスポンス
  • 📦 軽量 - 標準ライブラリのみ、外部依存なし
  • 🔒 型安全 - 完全な型ヒント対応

🚀 クイックスタート

インストール

pip install lambapi

基本的な使用例

from lambapi import API, create_lambda_handler

def create_app(event, context):
    app = API(event, context)
    
    @app.get("/")
    def hello():
        return {"message": "Hello, lambapi!"}
    
    @app.get("/users/{user_id}")
    def get_user(user_id: str):
        return {"user_id": user_id, "name": f"User {user_id}"}
    
    @app.get("/search")
    def search(q: str = "", limit: int = 10):
        return {"query": q, "limit": limit, "results": []}
    
    return app

lambda_handler = create_lambda_handler(create_app)

ローカル開発

# 新しいプロジェクトを作成
lambapi create my-api --template basic

# ローカルサーバーを起動(ホットリロード付き)
lambapi serve app

# ブラウザで確認
curl http://localhost:8000/

📚 ドキュメント

完全なドキュメントは https://sskyh0208.github.io/lambapi/ で公開されています。

💡 なぜ lambapi?

従来の問題

# 従来の Lambda ハンドラー(煩雑)
def lambda_handler(event, context):
    method = event['httpMethod']
    path = event['path']
    query_params = event.get('queryStringParameters', {}) or {}
    limit = int(query_params.get('limit', 10))  # 手動型変換
    
    if method == 'GET' and path == '/users':
        # 複雑なルーティング...
        pass
    
    return {
        'statusCode': 200,
        'headers': {'Content-Type': 'application/json'},
        'body': json.dumps({'data': 'result'})
    }

lambapi なら

# lambapi 版(シンプル)
@app.get("/users")
def get_users(limit: int = 10):  # 自動型変換とデフォルト値
    return {"users": [f"user-{i}" for i in range(limit)]}

🛠️ 開発

開発環境のセットアップ

git clone https://github.com/sskyh0208/lambapi.git
cd lambapi
pip install -e ".[dev]"

テスト・品質チェック

pytest              # テスト実行
black .             # コードフォーマット
mypy lambapi        # 型チェック

🤝 コミュニティ

  • 📁 GitHub - ソースコード・ Issues ・ Discussions
  • 📦 PyPI - パッケージダウンロード
  • 📚 ドキュメント - 完全な使用ガイド

📄 ライセンス

MIT License - 詳細は LICENSE ファイルを参照

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

lambapi-0.1.4.tar.gz (77.0 kB view details)

Uploaded Source

Built Distribution

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

lambapi-0.1.4-py3-none-any.whl (40.0 kB view details)

Uploaded Python 3

File details

Details for the file lambapi-0.1.4.tar.gz.

File metadata

  • Download URL: lambapi-0.1.4.tar.gz
  • Upload date:
  • Size: 77.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.1 Linux/6.11.0-1018-azure

File hashes

Hashes for lambapi-0.1.4.tar.gz
Algorithm Hash digest
SHA256 fe5cb12c9f1d4f36ef758f2e88c9a9f02a3efc36e091dbbf4309dc3cab22d133
MD5 80c910b30f7addfee4f5586679e930f3
BLAKE2b-256 032119e9d943344ed205cc486e4bf6359f6a4a3ccee5ea3c290cf91ae778756d

See more details on using hashes here.

File details

Details for the file lambapi-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: lambapi-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 40.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.1 Linux/6.11.0-1018-azure

File hashes

Hashes for lambapi-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 733ee9a47caea57962bbe7e32ad2a9e35cc744ee5ed30144f8eeaa59a9671ceb
MD5 cfe147abff66dc9ad53f25f5624dcbe6
BLAKE2b-256 ce2c54a09d31362bcc52aa2458b5d679e8dc7f90d0f5e9cf9aa94a44742b0504

See more details on using hashes here.

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