Skip to main content

veil-api(Python バインディング、F-194)

veil の API サーバライブラリを Python から使うための PyO3 バインディングです。 HTTP の受理・TLS・HTTP/1.1・HTTP/2・HTTP/3・OpenAPI 配信は Rust 側(io_uring ベースの veil データプレーン)が担当し、 Python は FastAPI に似たデコレータでハンドラ関数だけを書きます。import 名は veil です。

インストール・ビルド

python3 -m venv .venv && . .venv/bin/activate
pip install maturin
cd crates/veil-python
maturin develop --release        # 開発用: venv にインストール
maturin build --release          # wheel を作る(target/wheels/)
pip install pydantic             # 任意(モデルによる本文検証・スキーマ生成)

abi3(Python 3.9 以上、1 つの wheel で全バージョン)です。

使い方

import veil

@veil.get("/ping", offload=False)
def ping():
    return "pong"

@veil.get("/hello/{name}")
def hello(name: str, greeting: str = "Hello"):       # name=パス、greeting=クエリ(注釈で型変換)
    return {"message": f"{greeting}, {name}"}

@veil.post("/users", status_code=201,
           body_constraints={"name": {"type": "string", "minLength": 1, "maxLength": 50, "required": True},
                             "age": {"type": "integer", "minimum": 0, "maximum": 120, "required": True}})
def create_user(body: dict):
    return body

veil.run(listen_cleartext="127.0.0.1:8000")      # Ctrl-C / SIGTERM で graceful に停止

FastAPI のように app = veil.App(title=..., version=...) を作って @app.get(...)、app.run() も使えます。 サンプルは examples/api/python-hello/・examples/api/python-fastapi-like/ にあります。

引数の束縛(inspect.signature)

引数 束縛
名前が req / request、または veil.Request 注釈 リクエスト(method・path・query・headers・body・json()・text()・params・query_params・client_ip)
パスの {name} と同名 パスパラメータ(int/float/bool/str 注釈で変換。失敗は 422)
pydantic BaseModel 注釈、名前 body、dict/list 注釈 JSON 本文(pydantic があれば model_validate_json。失敗は FastAPI 形の 422)
それ以外 クエリパラメータ(既定値あり=任意、無し=必須。欠落・変換失敗は 422)

戻り値

dict/list/数値 → JSON、str → text/plain、bytes → application/octet-stream、veil.Response / JSONResponse、 (body, status)、pydantic モデル → JSON、None → 204。status_code= は既定の 200 を置き換えます。 raise veil.HTTPException(404, "not found") → {"detail": "not found"}。ハンドラの未処理例外は トレースバックを標準エラーに出して 500 {"detail":"Internal Server Error"} を返します。

body_constraints(pydantic 無しの検証)

minimum / maximum / exclusiveMinimum / exclusiveMaximum / minLength / maxLength / pattern(re.fullmatch)/ enum / type を辞書本文のフィールドごとに検証します(違反は 422)。必須は {"required": ["age"]}(トップレベル)または フィールド内の "required": True。同じ内容が OpenAPI の requestBody に反映されます。

OpenAPI

各ルートの Operation Object(operationId=関数名、docstring の要約・説明、tags、パス/クエリのパラメータ、requestBody、 422 応答)を Python 側で作って veil に渡します。/openapi.json と /docs(Swagger UI)に載ります。 pydantic モデルのスキーマは components.schemas に入ります。run(openapi=False) で無効化できます。

offload(GIL とスレッド)

Python のハンドラは GIL を握って実行されます。

  • 既定(offload=True): veil のハンドラ用プール([api] handler_threads)へ退避して実行します。 イベントループ(ワーカースレッド)は GIL 待ちで止まらず、I/O を捌き続けます。
  • offload=False: ワーカースレッド上で直接呼びます。自明に軽い処理(定数応答など)専用です。 重い処理・ブロッキング I/O・長い GIL 保持を置くと、そのワーカーが担当する全接続が止まります。

veil.run() は GIL を解放して起動します。async 関数はハンドラ用プールのスレッドごとに 1 つのイベントループで実行されます(F-212)。 Python は純粋な Python ハンドラの並列度を GIL に制限されるため、CPU バウンドな処理は別プロセス構成を検討してください。

ストリーミング(F-210)

@veil.get("/stream")
def stream():                      # ジェネレータ(非同期ジェネレータも可)は断片ごとに text/plain で送る
    for i in range(3):
        yield f"line {i}\n"

@veil.get("/sse")
def sse():                         # Server-Sent Events。要素は str・JSON にできる値・{"event", "data", "id", "retry"}
    return veil.EventSourceResponse({"event": "tick", "data": {"n": i}} for i in range(3))

@veil.get("/file")
def file():
    return veil.StreamingResponse(open("big.bin", "rb"), media_type="application/octet-stream",
                                  trailers=[("x-checksum", "...")])

@veil.post("/upload", stream_body=True)   # 本文が届く前に呼ぶ
def upload(req: veil.Request):
    return str(sum(len(c) for c in req.stream()))   # 届いた順に読む

ストリーミングの応答はハンドラ用プールのスレッドで反復します(offload=False のルートでは全量を作ってから送ります)。 クライアントが切断すると反復を止めます。

gRPC(F-210)

veil はメッセージの直列化に依存しません(protobuf・betterproto・JSON 等を利用者が選びます)。2 つの層があります。

基本の層(依存なし) — grpcio と同じ引数名:

import veil, veil.grpc
from demo_pb2 import HelloRequest, HelloReply

@veil.grpc.unary_unary("/demo.v1.Demo/SayHello",
                       request_deserializer=HelloRequest.FromString,
                       response_serializer=HelloReply.SerializeToString)
def say_hello(request, context):
    return HelloReply(message="Hello " + request.name)

veil.grpc.add_health()                            # grpc.health.v1.Health
veil.run(listen_cleartext="127.0.0.1:50051")

unary_stream・stream_unary・stream_stream も同じ形で、ストリーミングの入力は反復子、出力は反復子・ジェネレータです。 直列化関数を省くと bytes のまま受け渡します。async def と非同期ジェネレータも使えます。

grpcio の層(pip install veil-api[grpc]) — grpc_tools.protoc の生成コードをそのまま使う:

server = veil.grpc.Server()
demo_pb2_grpc.add_DemoServicer_to_server(MyServicer(), server)
server.add_insecure_port("127.0.0.1:50051")
server.start(); server.wait_for_termination()     # = veil.run(listen_cleartext=...)

context は grpcio の ServicerContext の主要部分(abort・abort_with_status・set_code・set_details・ invocation_metadata・send_initial_metadata・set_trailing_metadata・time_remaining・is_active・peer)を持ち、 状態コードは grpc.StatusCode も veil.grpc.StatusCode も受けます。TLS(HTTP/2・HTTP/3)は app.run(listen=..., tls_cert=..., tls_key=...) で使います(add_secure_port はありません)。 圧縮・期限・gRPC-Web・[api] grpc_* の設定は Rust のハンドラと同じです。 サンプル: examples/api/python-grpc/(VEIL_GRPC_MODE=grpcio|plain)。

L4(TCP・UDP、F-210)

@veil.l4_tcp("echo", "127.0.0.1:7000")
class Echo(veil.Protocol):                 # asyncio.Protocol と同じ名前
    def data_received(self, data):
        self.transport.write(data)         # コールバックの中でだけ

@veil.l4_udp("udp_echo", "127.0.0.1:7001")
def udp_echo(data, peer):                  # peer = (host, port)。bytes を返すと応答、None は無応答
    return data

コールバックはハンドラ用プールで、接続ごとに 1 つずつ順に呼ばれます。

GraphQL

veil は GraphQL の実装を持ちません。好きなライブラリを普通のルートとして載せます。 examples/api/python-graphql/ は strawberry(クエリ・ミューテーション・SSE のサブスクリプション)の例です。

設定

veil.run(config_path=None, *, listen_cleartext=None, listen=None, tls_cert=None, tls_key=None, threads=None, overrides=None, openapi=True)。 overrides は {"server.threads": 4, "api.max_body_size": 1048576} のようにキー → Python 値(TOML に変換)です。 環境変数 VEIL_OVERRIDE_<n> も使えます。キーは examples/config.toml を参照してください。 veil.Config(from_file・set・listen_cleartext・listen・tls・threads・to_toml)を直接組み立てることもできます。

テスト

python -I tests/test_binding.py                  # 純 Python の単体テスト(ネイティブ拡張不要)
PYTHON=$(which python) tests/e2e.sh              # maturin develop 後。サンプルを起動して curl(HTTP/1.1 と h2c)で検証

Metadata

Release files for veil-api 0.8.1

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

Source distribution (sdist)

Source distribution for veil-api 0.8.1
File Size Uploaded Provenance
veil_api-0.8.1.tar.gz 3.0 MB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for veil-api 0.8.1
File
veil_api-0.8.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
veil_api-0.8.1-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details
veil_api-0.8.1-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details
veil_api-0.8.1-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details
veil_api-0.8.1-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details
veil_api-0.8.1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
veil_api-0.8.1-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 51.8 MB

Release files / veil_api-0.8.1.tar.gz

Download URL veil_api-0.8.1.tar.gz
Size 3.0 MB
Tags Source
SHA-256 checksum
How to use checksums
7bfe04e2201d24f9eaf5bb144a5f000d73c342e62365c0b05ec42a6e251e4cb7
BLAKE2b-256 checksum
How to use checksums
4a19b9afb7d2cd79eecad7916f323bbe8d299c3aa2f486829962ffcaea709456
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 20, 2026.

Transparency log

Release files / veil_api-0.8.1-cp39-abi3-win_amd64.whl

Download URL veil_api-0.8.1-cp39-abi3-win_amd64.whl
Size 6.8 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
a6c6f927e4fdc3234d7940bab4e65277c83a4f12931ed05748b44ca502c3d0cf
BLAKE2b-256 checksum
How to use checksums
1df475037c87d70d821e4752929776a9688ba646be45744771a1c705902cdc5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 20, 2026.

Transparency log

Release files / veil_api-0.8.1-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL veil_api-0.8.1-cp39-abi3-musllinux_1_2_x86_64.whl
Size 7.3 MB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
7617d9d2328fec47c1d6554d113574f644e6e0f4c3c84675b3399720ce22a7ae
BLAKE2b-256 checksum
How to use checksums
caeb5ae2189b19551705596ceb7031fda6784692415217fbdfbb3e153d37bbe5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 20, 2026.

Transparency log

Release files / veil_api-0.8.1-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL veil_api-0.8.1-cp39-abi3-musllinux_1_2_aarch64.whl
Size 7.1 MB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
68cb23740a48b66fceccfb7843e3d9d1e470e7161f21c117cc02360f63f2dfb2
BLAKE2b-256 checksum
How to use checksums
1eae8738c06764d84c5cb52e9d3776f88c843be2b4754bbcf635f946e98b2dc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 20, 2026.

Transparency log

Release files / veil_api-0.8.1-cp39-abi3-manylinux_2_28_x86_64.whl

Download URL veil_api-0.8.1-cp39-abi3-manylinux_2_28_x86_64.whl
Size 7.1 MB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
7ceb6e55ceaa9cf5deca12e442d39377ac35631d19ca0d8ac65e91acf9ad86e4
BLAKE2b-256 checksum
How to use checksums
a44b2a6f4ebdbe92a4779cf336394094f602ad93efb750801ef0cdcb011df56a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 20, 2026.

Transparency log

Release files / veil_api-0.8.1-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL veil_api-0.8.1-cp39-abi3-manylinux_2_28_aarch64.whl
Size 6.9 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
d70fde5fdd66c5dd6578a62d25ef5ef5d802549275fb9c11e0e5d3a0e5eea2da
BLAKE2b-256 checksum
How to use checksums
c2a023ad8988e47c38f5225427f68487ae0494c35ce8621057c5cbb2e1b70fed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 20, 2026.

Transparency log

Release files / veil_api-0.8.1-cp39-abi3-macosx_11_0_arm64.whl

Download URL veil_api-0.8.1-cp39-abi3-macosx_11_0_arm64.whl
Size 6.7 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
58e218fc132d9406d20a296ce73c63b7d59765bed0bd5d586024e83b20e72f12
BLAKE2b-256 checksum
How to use checksums
a3636ff713ecb5270ad5da80d031cf7d330aa25aedffdb2b445afa9a7f208195
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 20, 2026.

Transparency log

Release files / veil_api-0.8.1-cp39-abi3-macosx_10_12_x86_64.whl

Download URL veil_api-0.8.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 7.0 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
bb293097f239d88bf9b2aa336ed62b97428350e64214e5a8596f2f362c4f8c8b
BLAKE2b-256 checksum
How to use checksums
6f88546cfceb29e8f4b2ce744baa38bc1f7026146ae9af8c0f3b3271acfc3482
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 20, 2026.

Transparency log

Security for veil-api 0.8.1

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 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for veil_api-0.8.1.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 Oct 20, 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.

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