インストールと起動¶
必要環境¶
- Python 3.10以上
PyPIからwheelをインストールする場合、RustやC/C++ build toolsは不要です。 ソースからbuildする場合のみRust stableと対応するリンカーが必要です。
インストール¶
公開パッケージは pypi.org/project/higuma で確認できます。
WindowsでPythonとRustのarchitectureが異なる場合は、先にtargetを追加します。
対応プラットフォーム¶
0.1.0 はCPython stable ABIを使うため、1つのwheelでPython 3.10以降に対応します。
| OS | Architecture |
|---|---|
| Windows | x86_64 |
| Linux glibc | x86_64、aarch64 |
| Linux musl / Alpine | x86_64 |
| macOS | Intel x86_64、Apple Silicon arm64 |
対応wheelがない環境ではsdistからbuildされるため、Rust toolchainが必要です。
アプリを作る¶
app.py
from higuma import Higuma, request
app = Higuma(__name__)
@app.get("/")
def home():
return "<h1>It works</h1>"
@app.post("/api/echo")
def echo():
return {"received": request.json}
起動する¶
開発サーバーは http://127.0.0.1:8000 で待ち受けます。
テストする¶
ネットワークを起動しない高速なテストクライアントを利用できます。
test_app.py
from app import app
def test_home():
client = app.test_client()
response = client.get("/")
assert response.status_code == 200
assert "It works" in response.text