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.5.tar.gz (76.6 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.5-py3-none-any.whl (39.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lambapi-0.1.5.tar.gz
  • Upload date:
  • Size: 76.6 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.5.tar.gz
Algorithm Hash digest
SHA256 f701b4bed6e1e75b2b67a76b02cade6426ae1235bdacca318d24a6ddecb54ee0
MD5 f9275f4b47a97646cfa38a84baba5be4
BLAKE2b-256 b09c3963c54d0bd2ae09ccaee085a0319be0f38d57862886c309e88908ccaaa6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lambapi-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 39.6 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 53b62feb2fc8bd0cb808133c7250bf241ac77c94ba517196fff8e564dfabf3e8
MD5 574e81c1b1d800cd8f83e9a5c65c2955
BLAKE2b-256 12886979bec3456ca1ed2eab3933610c5aa38603da6be156a20ae21f1ed4f78c

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