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]"

Pre-commit フックのセットアップ

# CI と同じチェックをコミット前に実行
./scripts/setup-pre-commit.sh

テスト・品質チェック

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

# または一括実行
pre-commit run --all-files

🤝 コミュニティ

  • 📁 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.6.tar.gz (77.1 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.6-py3-none-any.whl (40.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lambapi-0.1.6.tar.gz
Algorithm Hash digest
SHA256 a8e8e634bc25e97139e6bd4b4c353eb4f2192e40f1fefdb2a3d0c5b56dd0cf02
MD5 d987bf140aea188e1d4f03ffb54a5f73
BLAKE2b-256 a8885f9034c7776a7978476f518af7856277caf0b5c7c4e12a81fd0d1f5e92ce

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for lambapi-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 056494765c9a8c360c240db5605f5566524d07c4ebe0392b06180400c4e7b3f8
MD5 192b4f22905c2d812a1f13cf123bb115
BLAKE2b-256 5c883bd8a0b0cb4a9b3076e1e076b25db01597c0ad54af2193b8670cbf33fd4a

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