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.2.1.tar.gz (87.5 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.2.1-py3-none-any.whl (48.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lambapi-0.2.1.tar.gz
  • Upload date:
  • Size: 87.5 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.2.1.tar.gz
Algorithm Hash digest
SHA256 68757fc693029b8adec40f1e5bb31393edfc91c85955fd85946bdcba8d67df69
MD5 59fb7331da1e56c7a927c538f05daa5d
BLAKE2b-256 92136bfbd20744553743da528ac52b8fcfc8f249beb4b7d790ab153a856f22f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lambapi-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 48.5 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 90806b2c165acd6171b22c5a4394f5bef686a843902ba7116a0100311962f5fc
MD5 7ae063d27451888c88edc9717a560918
BLAKE2b-256 7ca265882d308f41336e35145fe5acb46c59041a55287786e479295c9c1909ff

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