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.0

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.0
File Size Uploaded Provenance
veil_api-0.8.0.tar.gz 3.0 MB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for veil-api 0.8.0
File
veil_api-0.8.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
veil_api-0.8.0-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details
veil_api-0.8.0-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details
veil_api-0.8.0-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details
veil_api-0.8.0-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details
veil_api-0.8.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
veil_api-0.8.0-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.0.tar.gz

Download URL veil_api-0.8.0.tar.gz
Size 3.0 MB
Tags Source
SHA-256 checksum
How to use checksums
07dd5308b4818ac3802dbc77032f0555e2863dadbea228134ba384e088ea7c46
BLAKE2b-256 checksum
How to use checksums
3ae64535ae942dca55cfd141ac5be12493fa6a850809d4b83b76913233ed2c90
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 19, 2026.

Transparency log

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

Download URL veil_api-0.8.0-cp39-abi3-win_amd64.whl
Size 6.8 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
cdeca35eaad550aaecf324ac0c8604d563d809c5d9218b9357c1205b1d045240
BLAKE2b-256 checksum
How to use checksums
13b0cb52a1f5cf926cdb64310568c02b9848572f7750353a8c2aa1b0d747c994
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 19, 2026.

Transparency log

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

Download URL veil_api-0.8.0-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
ed8ed0e61048f82bd8d060221996036948b463662d9bafcca2e3c52eaaa8d3f7
BLAKE2b-256 checksum
How to use checksums
3a2a84c8e3daed9d795c42295c8ecf5e98d6ebdebd232fb3260c55952e8fd1ca
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 19, 2026.

Transparency log

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

Download URL veil_api-0.8.0-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
f9f47eeb0ee80e8910d696a6ced14417d5dc092e6b2f26d39bcfcadde9e8d7d6
BLAKE2b-256 checksum
How to use checksums
c9955d6dd3d617c37012d3f5345202a78fb7764832a6a1256693815f9a4b7558
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 19, 2026.

Transparency log

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

Download URL veil_api-0.8.0-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
4ea23ec385f9ffbdd8ff2bee904db7078fad43fd8ce496ffe77a5cb3ae668089
BLAKE2b-256 checksum
How to use checksums
73633b10dc82c28bed21c404843528fa95c6072b051ef0374c37dc97602775d5
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 19, 2026.

Transparency log

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

Download URL veil_api-0.8.0-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
f3251420b8d8b2153ead32d0591ceb4ec65bc9ff7bd8168f8ec16b17c497a245
BLAKE2b-256 checksum
How to use checksums
6bd7fd86bb96fb6953b2722d3bc4c39a70cbbcfc32ab1a140514f3d576a4660a
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 19, 2026.

Transparency log

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

Download URL veil_api-0.8.0-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
5152faa6fd8fd8479326bd2836b5a84940da7bd729f7b53dfb6f3495c867d2a5
BLAKE2b-256 checksum
How to use checksums
887e08a53eb3afbbdc7a25c87d02de768c3671d27935e33ae3257dfc9ca7610e
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 19, 2026.

Transparency log

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

Download URL veil_api-0.8.0-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
84900e54bfd2dcf987bdde75149848f1e9f1acc5645fa47d987c962bce544f67
BLAKE2b-256 checksum
How to use checksums
5846cc38d9ae3e99fd201b6048b9f534444adc81effe69eae09fa43a6db47362
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 19, 2026.

Transparency log

Security for veil-api 0.8.0

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.0.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 19, 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