Skip to main content

higuma — 日本のヒグマをモチーフにしたロゴ

higuma

Pythonで書き、Rustで配信する。
A Flask-inspired Python web framework with a Rust HTTP core.

CI Dependency security checks PyPI version Supported Python versions MIT license

日本語ドキュメント · English documentation · API reference · Examples · Releases


higumaは、書き慣れたPythonのdecorator APIに、axum / Tokioを使ったRustの実行基盤を 組み合わせたWebフレームワークです。JSON API、HTML SSR、リアルタイム通信を、 Python側の必須runtime dependencyなしで構築できます。 名前は日本のヒグマに由来します。

0.11.8 — ASGI 500 フォールバック時のヘッダ/HEAD 応答整合、不正 WebSocket scope/spec_version 耐性、 Python/Rust 双方での WebSocket same-origin 空 Host・:0 拒否と IPv6 正規化、Response.set_cookie() の timedelta 対応・属性インジェクション防止、StreamingResponse 全資源クローズ、Supervisor bind 失敗時の シグナル復元、Higuma.run()/CLI/WSGI マウント境界を改善。必須 Python 依存は 0 のままです。

0.11.7 — CORSMiddleware/TrustedHostMiddleware/ProxyHeadersMiddleware の単一文字列誤指定防止、 TokenSigner/RateLimitMiddleware/generate_user_id()・HealthChecks の入力検証と終了時同期、 Database.session() の lock リーク修正と Database.close() 追加、native add_route() の原子性確保、 from __future__ import annotations 下での CLI command 登録を改善。必須 Python 依存は 0 のままです。

0.11.6 — mount_wsgi("/")/mount_asgi("/")/static_url_path="/" の二重スラッシュ登録修正、 空 200 応答での Content-Length: 0 出力、URL-encoded form の MAX_FORM_PARTS 強制、 大文字小文字非依存 Range: bytes=・StreamingResponse header 正規化、ORM default 遅延評価・ limit(0).first()・未保存 delete() 防止を改善。必須 Python 依存は 0 のままです。

0.11.5 — PasswordHasher の OWASP scrypt (n>=2**15) 対応と 256 MiB 上限、 from __future__ import annotations 下のローカル dataclass/TypedDict 検証・OpenAPI 解決、 StaticFiles の root_path 維持リダイレクト、IPv6 Supervisor bind、multipart 7bit/RFC 2231、 ASGITestClient リダイレクト query 保持、非 ASCII 静的ルート url_for エンコードを改善。必須 Python 依存は 0 のままです。

0.11.4 — nativeサーバーの末尾/維持(mount_static(..., html=True)の無限リダイレクト解消)、 IPv6 bind・IPv6 WebSocket same-origin・close検証、RFC 9110重複header統合、 Observability middlewareの4xx/cancel記録、make_response重複header組・SSE改行仕様準拠、 認証・CSRF・OAuth2・ORM save()境界を改善。必須Python依存は0のままです。

0.11.3 — mount_asgiの非同期sub-app切断制御、堅牢なRequest.cookies解析、 MethodView/Viewの型付き引数・DI・OpenAPI対応、lifespanの同一イベントループ維持、 ASGITestClientのfollow_redirects対応を改善。必須Python依存は0のままです。

0.11.2 — ASGI監視・WebSocket切断時やhook差替時の終了処理、response.background再代入、 StreamingResponseのcontent_length・HEAD一貫性、native WebSocket/205応答の後処理を改善。 終了処理と運用上の境界。必須Python依存は0のままです。

0.11.1 — 非同期background、context内upload、stream完了・HEAD・切断時の後片付けを修正。 終了処理と運用上の境界。必須Python依存は0のままです。

0.11.0 — Flask風URL hooks、Blueprintのアプリ全体hooks、設定loader・階層付き環境変数、 JSON helper互換性を改善。使い方と移行時の注意。

0.11.0に含まれる0.10開発分 — 条件付きASGI高速経路、async DB、Flask風Signals、Redis共有session/quota、 request ID・metrics・任意tracing・health checks。導入と対応境界。

0.11.0に含まれる0.9開発分 — 親子Blueprint、独自CLI、非同期テストクライアント、任意のSQLAlchemy/Redis連携、 大容量入力のディスク退避を追加。Flask風のまま分割アプリを育てる開発体験を整えました。 開発ガイド / 連携と実用サンプル / アップロードの境界 / 実測と制約 / 変更履歴

はじめる · 型付きAPI · 機能 · フロントエンド · 対応範囲 · 運用 · 貢献する

Quick start

CPython 3.10以降でインストールできます。

python -m pip install -U higuma

app.pyを作成します。

from higuma import Higuma, request

app = Higuma(__name__)


@app.get("/")
def index():
    return {"message": "Hello from higuma"}


@app.post("/echo")
def echo():
    return {"received": request.json}


if __name__ == "__main__":
    app.run()

起動後、http://127.0.0.1:8000 を開きます。

python app.py

CLIからも起動できます。

higuma run app:app --host 127.0.0.1 --port 8000
higuma routes app:app
higuma run app:app --processes 4 --max-connections 1024

GETの応答を確認したら、Getting startedで request、template、CLIの使い方へ進めます。

型付きAPI

型付きAPIでは、標準のAnnotatedとdataclassだけで入力元、制約、dependency、出力を宣言できます。

from dataclasses import dataclass
from typing import Annotated

from higuma import Body, Depends, Higuma, QueryParam

app = Higuma(__name__)


@dataclass
class Item:
    name: str
    price: float


def page_size(limit: Annotated[int, QueryParam(ge=1, le=100)] = 20):
    return limit


@app.post("/items", response_model=Item, status_code=201)
def create_item(
    item: Annotated[Item, Body()],
    limit: Annotated[int, Depends(page_size)],
):
    return item

入力はruntimeで検証・変換され、不正時は構造化された422になります。schemaは同じ宣言から OpenAPI 3.1へ反映されます。

型付きルートの実行例はexamples/modern_typed_api.py、 宣言と制約の詳細はAPIリファレンスを参照してください。

主な機能

分野 機能
HTTP typed input、dependency injection、path converter、自動HEAD/OPTIONS、async handler
Response response model、HTML、JSON、cookie、Range file、sync/async streaming、background task
Realtime SSE、text/binary/JSON WebSocket、Origin検証、認証preflight、bounded queue
SSR MiniJinja、compiled template cache、context processor
構成 Blueprint、class-based view、lifespan、WSGI/ASGI mount、startup/shutdown hook
Flask風API(0.7.0以降) scoped Blueprint hooks/errors/templates、request context、after_this_request、request teardown
API設計 OpenAPI 3.1、Swagger UI、dataclass/TypedDict/enum/UUID/date schema
Data dependency-free SQLite ORM、transaction、pagination、typed field
Auth signed cookie session、login/role/permission、OAuth 2.0 + PKCE
Security scrypt password、signed token、CSRF、CORS、rate limit、trusted host/proxy
Operations test client、CLI、multi-process supervisor、worker restart limit
Server interfaces(0.8.0以降) app.asgi_app、app.wsgi_app、同じASGI loopでのasync lifespan / handler
Frontend(0.6.0以降) SPA history fallback、複数static root、Vite manifest、cache / MIME制御

完全な一覧と注意点は機能ガイドおよび APIリファレンスを参照してください。

Validationについて: Annotated[..., Body()]等のmarkerとresponse_modelはruntime検証を 有効にします。従来のrequest_body=やreturn annotation単独はschema metadataです。

CSR/SPAとフロントエンド

以下の機能にはhiguma 0.6.0以降が必要です。0.5.0から利用する場合は更新してください。

from higuma import Higuma

app = Higuma(__name__, static_folder=None)


@app.get("/api/status")
def status():
    return {"status": "ok"}


# 先にフロントエンドをビルドし、index.htmlを含む公開用フォルダを用意します。
app.mount_spa("/app", "frontend/dist")
  • CSR — 深いURLの再読み込みに対応し、APIや見つからないassetをHTMLに置き換えません。
  • 静的配信 — mount_static()で公開先を分離し、HTMLの再検証とassetのcacheを設定できます。
  • Vite + Python HTML — ViteManifestでhash付きJS・CSSとmodulepreloadを解決します。

React / Vue等のビルド、HMR、Node SSRの実行環境はフロントエンド側で用意します。 設置パス、cookie認証、CORS、デプロイの注意は フロントエンドガイド(English)を参照してください。

ASGI/WSGIで実行する

既存ASGI基盤にはasgi_app = app.asgi_app、WSGI基盤にはwsgi_app = app.wsgi_appを公開します。 例えばASGIでは、アプリmoduleにasgi_appを定義したうえで:

python -m pip install "higuma[asgi]"
uvicorn app:asgi_app --lifespan on --ws websockets-sansio

ASGIでも同期APIとの互換処理に専用workerを使用します。WSGIには標準WebSocket/lifespanがありません。 外部server利用時の性能や接続数、proxy trust、resourceの扱いは サーバーインターフェースガイドを確認してください。 Python必須runtime依存0は維持し、ASGI server関連は任意extraです。

対応範囲

  • Python: CPython 3.10以降(CIでは3.10〜3.14を検証)
  • OS: Windows x86-64、Linux x86-64 / ARM64、macOS x86-64 / Apple Silicon
  • Linux: manylinux wheelとmusllinux x86-64 wheelを配布
  • Database: 組み込みORMはSQLiteのみ
  • Protocol: 組み込みHTTP serverとWebSocket。TLSはreverse proxyで終端

wheelがないplatformではsource distributionからRust buildが必要です。公開済みの配布物は PyPIで確認できます。

互換性と設計上の境界

higumaはFlaskのdrop-in replacementではありません。組み込みRust serverに加え、 0.8.0からapp.asgi_app/app.wsgi_appを外部サーバーへ渡せます。

既存のWSGI / ASGI applicationはHTTPのroute配下へmountできますが、mount先の WebSocket、ASGI lifespan、無期限streamingを提供するものではありません。 組み込みのbackground taskとrate limitはprocess-localです。耐久性のあるjobや 分散状態には外部基盤を使用してください。

詳細はFlask互換性 / English compatibility guideと 機能対応表にまとめています。

Examples

examples/には、最小アプリだけでなく次の実行例があります。

  • routing、async handler、型付き入力、dependency injection、class-based view
  • response、cookie、file、multipart upload、streaming、SSE、background task
  • Blueprint、lifespan、WebSocket、WSGI/ASGI mount、OpenAPI
  • SQLite ORM、session authentication、role/permission、OAuth
  • security middleware、signed token、in-process testing
  • multi-process supervisor
やりたいこと 実行例
型付きAPI・入力検証 modern_typed_api.py
session・context・flash flask_compat.py
Blueprint hooks・CSRF・session保存 flask_lifecycle.py
既存Flaskアプリを接続 flask_mount.py
組み込み・ASGI・WSGIで同じアプリを実行 server_modes.py
リアルタイムチャット websocket_chat.py
streaming・SSE streaming_sse.py
SQLiteとtransaction orm_blog.py
認証・CSRF・proxy設定 security_hardened.py
CSR / Vite連携(0.6.0以降) csr_app.py / vite_ssr.py

必要な環境変数と実行コマンドはExamplesガイドに まとめています。

本番運用

higumaは活発に開発中です。本番採用前に、対象アプリケーションで負荷試験、障害試験、 security reviewを実施してください。

  • debug=Falseのまま運用する
  • Caddy、nginx、Cloudflare等でTLSを終端しHTTPSを強制する
  • 32バイト以上の推測不能なsecretをsecret managerから読み込む
  • TrustedHostMiddlewareと、正確なCORS / WebSocket Originを設定する
  • ProxyHeadersMiddlewareでは直接接続するproxyだけを信頼する
  • upload size、保存先、拡張子をアプリケーション側でも制限する
  • SQLite fileを定期backupし、multi-process時のwrite負荷を測定する
  • network timeout、request buffering、connection limitはreverse proxyでも設定する

詳しくはデプロイガイドと Security Policyを参照してください。

開発とコントリビューション

不具合報告、回帰テスト、ドキュメント改善、互換性の検証を歓迎します。 開発環境の準備にはRust toolchainも必要です。

python -m pip install -e ".[dev,docs]"
python -m pytest
python -m ruff check python tests examples
python -m ruff format --check python tests examples
cargo fmt --all -- --check
cargo clippy --locked --all-targets --all-features -- -D warnings
cargo test --locked --all-features
mkdocs build --strict

変更前にCONTRIBUTING.mdと、coding agent向けの SKILL.mdを確認してください。

CIではPython / OSのmatrix test、Rustのtest / lint、docs build、配布wheelのsmoke testを 実行します。依存関係の監査は専用workflowで 実施します。バッジは各workflowへのリンクであり、脆弱性が存在しないことの保証ではありません。

不具合はIssue trackerへ、 脆弱性は公開IssueではなくSecurity Policyの窓口へ報告してください。

ライセンス

MIT License

Metadata

Release files for higuma 0.11.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for higuma 0.11.8
File Size Uploaded Provenance Actions
higuma-0.11.8.tar.gz 1.3 MB With provenance Details for higuma-0.11.8.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for higuma 0.11.8
File Actions
higuma-0.11.8-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for higuma-0.11.8-cp310-abi3-win_amd64.whl
higuma-0.11.8-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for higuma-0.11.8-cp310-abi3-musllinux_1_2_x86_64.whl
higuma-0.11.8-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for higuma-0.11.8-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
higuma-0.11.8-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for higuma-0.11.8-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
higuma-0.11.8-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for higuma-0.11.8-cp310-abi3-macosx_11_0_arm64.whl
higuma-0.11.8-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for higuma-0.11.8-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 11.7 MB

Release files / higuma-0.11.8.tar.gz

Download URL higuma-0.11.8.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
77070c9971201f14c70a83e633e92247c3341b558f2ac2ee10e437a1764ce470
BLAKE2b-256 checksum
How to use checksums
075d8cafc1eb1827e00439320ecffbc424d49099c1e0fb2d4e4cec26c360e99e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / higuma-0.11.8-cp310-abi3-win_amd64.whl

Download URL higuma-0.11.8-cp310-abi3-win_amd64.whl
Size 1.7 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
307c7915e13b58605d8a73ef410eabaee8c413e91134a43349cc2f411ea1744e
BLAKE2b-256 checksum
How to use checksums
70d9dc7b91fb659721194100c10d788831f609bc312c48ef73fa254e1465efc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / higuma-0.11.8-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL higuma-0.11.8-cp310-abi3-musllinux_1_2_x86_64.whl
Size 2.0 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
199d2d797bae60a06201287bdac5c252b67e613c076137d9a845282dfb6da486
BLAKE2b-256 checksum
How to use checksums
47b3b65195d4da47b3eed8488a6d12d0ed17f228310a6544b1887e8848479ff8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / higuma-0.11.8-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL higuma-0.11.8-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.7 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
69f0c4d21299da1adef7c4b5335eec5c4f51caf8387b7748f053ae5d6dbd6717
BLAKE2b-256 checksum
How to use checksums
0c07c1ecc08c0e1a96e814dcaf8ca8023d4e93f8d1fb5a00ae098e25153f3929
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / higuma-0.11.8-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL higuma-0.11.8-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.7 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
cc8e4cc1b2ff8c606c1af3c068949813342cd769db5a9600c3319943e17cc315
BLAKE2b-256 checksum
How to use checksums
51e279fe8efd71c214358d29216f51c1e6bbe223a862e6dea8855be6483c57d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / higuma-0.11.8-cp310-abi3-macosx_11_0_arm64.whl

Download URL higuma-0.11.8-cp310-abi3-macosx_11_0_arm64.whl
Size 1.6 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c7a9ea0d081b75c0c0c151b1a3defd21139dbb14fe17a789802899cf14d8e0c0
BLAKE2b-256 checksum
How to use checksums
0033e51e3d0a380db5d993aad312cdb8294607f0d841fc7eb3f80b1c1f5fa0a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / higuma-0.11.8-cp310-abi3-macosx_10_12_x86_64.whl

Download URL higuma-0.11.8-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.7 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
8902bfb7908a542405a1b63489391a1866cd311f909e59c3eae55147f1b8d061
BLAKE2b-256 checksum
How to use checksums
b76fee5585aa65bf30c2be200bdf2a96e4178eb6c3d4a6aa813acb3038d691a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for higuma 0.11.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestation for higuma-0.11.8.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.11.8 This release

7 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page