HTTP Transport¶
HTTP transport using Falcon (server) and httpx (client). Requires pip install vgi-rpc[http].
Quick Start¶
Server¶
Create a WSGI app and serve it with any WSGI server (waitress, gunicorn, etc.):
from vgi_rpc import RpcServer, make_wsgi_app
server = RpcServer(MyService, MyServiceImpl())
app = make_wsgi_app(server)
# serve `app` with waitress, gunicorn, etc.
Client¶
from vgi_rpc import http_connect
with http_connect(MyService, "http://localhost:8080") as proxy:
result = proxy.echo(message="hello") # proxy is typed as MyService
Testing (no real server)¶
make_sync_client wraps a Falcon TestClient so you can test the full HTTP stack in-process:
from vgi_rpc import RpcServer
from vgi_rpc.http import http_connect, make_sync_client
server = RpcServer(MyService, MyServiceImpl())
client = make_sync_client(server)
with http_connect(MyService, client=client) as proxy:
assert proxy.echo(message="hello") == "hello"
Landing Page¶
By default, GET {prefix} (e.g. GET /vgi) returns an HTML landing page showing the vgi-rpc logo, the protocol name, server ID, and links. When the server has enable_describe=True, the landing page includes a link to the describe page.
To disable the landing page:
POST {prefix} returns 405 Method Not Allowed — it does not interfere with RPC routing.
Describe Page¶
When the server has enable_describe=True, GET {prefix}/describe (e.g. GET /vgi/describe) returns an HTML page listing all methods, their parameters (name, type, default), return types, docstrings, and method type badges (UNARY / STREAM). The __describe__ introspection method is filtered out.
Both enable_describe=True on the RpcServer and enable_describe_page=True (the default) on make_wsgi_app() are required.
To disable only the HTML page while keeping the __describe__ RPC method available:
Reserved path
When the describe page is active, the path {prefix}/describe is reserved for the HTML page. If your service has an RPC method literally named describe, you must set enable_describe_page=False.
Not-Found Page¶
By default, make_wsgi_app() installs a friendly HTML 404 page for any request that does not match an RPC route. If someone navigates to the server root or a random path in a browser, they see the vgi-rpc logo, the service protocol name, and a link to vgi-rpc.query.farm instead of a generic error.
This does not affect RPC clients — a request to a valid RPC route for a non-existent method still returns a machine-readable Arrow IPC error with HTTP 404.
To disable the page:
API Reference¶
Server¶
make_wsgi_app
¶
make_wsgi_app(
server: RpcServer,
*,
prefix: str = "",
signing_key: bytes | None = None,
max_stream_response_bytes: int | None = None,
max_stream_response_time: float | None = None,
max_request_bytes: int | None = None,
authenticate: (
Callable[[Request], AuthContext] | None
) = None,
cors_origins: str | Iterable[str] | None = None,
cors_max_age: int | None = 7200,
upload_url_provider: UploadUrlProvider | None = None,
max_upload_bytes: int | None = None,
otel_config: object | None = None,
sentry_config: object | None = None,
token_ttl: int = 3600,
compression_level: int | None = 3,
enable_not_found_page: bool = True,
enable_landing_page: bool = True,
enable_describe_page: bool = True,
repo_url: str | None = None,
oauth_resource_metadata: (
OAuthResourceMetadata | None
) = None
) -> App[Request, Response]
Create a Falcon WSGI app that serves RPC requests over HTTP.
| PARAMETER | DESCRIPTION |
|---|---|
server
|
The RpcServer instance to serve.
TYPE:
|
prefix
|
URL prefix for all RPC endpoints (default
TYPE:
|
signing_key
|
HMAC key for signing state tokens. When
TYPE:
|
max_stream_response_bytes
|
When set, producer stream responses may
buffer multiple batches in a single HTTP response up to this
size before emitting a continuation token. The client
transparently resumes via
TYPE:
|
max_stream_response_time
|
When set, producer stream responses may
buffer multiple batches up to this many seconds of wall time
before emitting a continuation token. Can be combined with
TYPE:
|
max_request_bytes
|
When set, the value is advertised via the
TYPE:
|
authenticate
|
Optional callback that extracts an :class:
TYPE:
|
cors_origins
|
Allowed origins for CORS. Pass
TYPE:
|
cors_max_age
|
Value for the
TYPE:
|
upload_url_provider
|
Optional provider for generating pre-signed
upload URLs. When set, the
TYPE:
|
max_upload_bytes
|
When set (and
TYPE:
|
otel_config
|
Optional
TYPE:
|
sentry_config
|
Optional
TYPE:
|
token_ttl
|
Maximum age of stream state tokens in seconds. Tokens
older than this are rejected with HTTP 400. Default is 3600
(1 hour). Set to
TYPE:
|
compression_level
|
Zstandard compression level for HTTP request/
response bodies.
TYPE:
|
enable_not_found_page
|
When
TYPE:
|
enable_landing_page
|
When
TYPE:
|
enable_describe_page
|
When
TYPE:
|
repo_url
|
Optional URL to the service's source repository (e.g. a GitHub URL). When provided, a "Source repository" link appears on the landing page and describe page.
TYPE:
|
oauth_resource_metadata
|
Optional
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
App[Request, Response]
|
A Falcon application with routes for unary and stream RPC calls. |
Source code in vgi_rpc/http/_server.py
1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 | |
Client¶
http_connect
¶
http_connect(
protocol: type[P],
base_url: str | None = None,
*,
prefix: str | None = None,
on_log: Callable[[Message], None] | None = None,
client: Client | _SyncTestClient | None = None,
external_location: ExternalLocationConfig | None = None,
ipc_validation: IpcValidation = FULL,
retry: HttpRetryConfig | None = None,
compression_level: int | None = 3
) -> Iterator[P]
Connect to an HTTP RPC server and yield a typed proxy.
| PARAMETER | DESCRIPTION |
|---|---|
protocol
|
The Protocol class defining the RPC interface.
TYPE:
|
base_url
|
Base URL of the server (e.g.
TYPE:
|
prefix
|
URL prefix matching the server's prefix. When
TYPE:
|
on_log
|
Optional callback for log messages from the server.
TYPE:
|
client
|
Optional HTTP client —
TYPE:
|
external_location
|
Optional ExternalLocationConfig for resolving and producing externalized batches.
TYPE:
|
ipc_validation
|
Validation level for incoming IPC batches.
TYPE:
|
retry
|
Optional retry configuration for transient HTTP failures.
When
TYPE:
|
compression_level
|
Zstandard compression level for request bodies.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
P
|
A typed RPC proxy supporting all methods defined on protocol. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If base_url is |
Source code in vgi_rpc/http/_client.py
http_introspect
¶
http_introspect(
base_url: str | None = None,
*,
prefix: str | None = None,
client: Client | _SyncTestClient | None = None,
ipc_validation: IpcValidation = FULL,
retry: HttpRetryConfig | None = None
) -> ServiceDescription
Send a __describe__ request over HTTP and return a ServiceDescription.
| PARAMETER | DESCRIPTION |
|---|---|
base_url
|
Base URL of the server (e.g.
TYPE:
|
prefix
|
URL prefix matching the server's prefix.
TYPE:
|
client
|
Optional HTTP client (
TYPE:
|
ipc_validation
|
Validation level for incoming IPC batches.
TYPE:
|
retry
|
Optional retry configuration for transient HTTP failures.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ServiceDescription
|
A |
| RAISES | DESCRIPTION |
|---|---|
RpcError
|
If the server does not support introspection or returns an error. |
ValueError
|
If base_url is |
Source code in vgi_rpc/http/_client.py
http_capabilities
¶
http_capabilities(
base_url: str | None = None,
*,
prefix: str | None = None,
client: Client | _SyncTestClient | None = None,
retry: HttpRetryConfig | None = None
) -> HttpServerCapabilities
Discover server capabilities via an OPTIONS request.
Sends OPTIONS {prefix}/__capabilities__ and reads capability
headers (VGI-Max-Request-Bytes, VGI-Upload-URL-Support,
VGI-Max-Upload-Bytes) from the response.
| PARAMETER | DESCRIPTION |
|---|---|
base_url
|
Base URL of the server (e.g.
TYPE:
|
prefix
|
URL prefix matching the server's prefix.
TYPE:
|
client
|
Optional HTTP client (
TYPE:
|
retry
|
Optional retry configuration for transient HTTP failures.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HttpServerCapabilities
|
An |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If base_url is |
Source code in vgi_rpc/http/_client.py
request_upload_urls
¶
request_upload_urls(
base_url: str | None = None,
*,
count: int = 1,
prefix: str | None = None,
client: Client | _SyncTestClient | None = None,
retry: HttpRetryConfig | None = None
) -> list[UploadUrl]
Request pre-signed upload URLs from the server's __upload_url__ endpoint.
The server must have been configured with an upload_url_provider
in make_wsgi_app().
| PARAMETER | DESCRIPTION |
|---|---|
base_url
|
Base URL of the server (e.g.
TYPE:
|
count
|
Number of upload URLs to request (default 1, max 100).
TYPE:
|
prefix
|
URL prefix matching the server's prefix.
TYPE:
|
client
|
Optional HTTP client (
TYPE:
|
retry
|
Optional retry configuration for transient HTTP failures.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[UploadUrl]
|
A list of |
| RAISES | DESCRIPTION |
|---|---|
RpcError
|
If the server does not support upload URLs (404) or returns an error. |
ValueError
|
If base_url is |
Source code in vgi_rpc/http/_client.py
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 | |
Capabilities¶
HttpServerCapabilities
dataclass
¶
HttpServerCapabilities(
max_request_bytes: int | None = None,
upload_url_support: bool = False,
max_upload_bytes: int | None = None,
)
Capabilities advertised by an HTTP RPC server.
| ATTRIBUTE | DESCRIPTION |
|---|---|
max_request_bytes |
Maximum request body size the server advertises,
or
TYPE:
|
upload_url_support |
Whether the server supports the
TYPE:
|
max_upload_bytes |
Maximum upload size the server advertises for
client-vended URLs, or
TYPE:
|
Stream Session¶
HttpStreamSession
¶
HttpStreamSession(
client: Client | _SyncTestClient,
url_prefix: str,
method: str,
state_bytes: bytes | None,
output_schema: Schema,
on_log: Callable[[Message], None] | None = None,
*,
external_config: ExternalLocationConfig | None = None,
ipc_validation: IpcValidation = FULL,
pending_batches: list[AnnotatedBatch] | None = None,
finished: bool = False,
header: object | None = None,
retry_config: HttpRetryConfig | None = None,
compression_level: int | None = None
)
Client-side handle for a stream over HTTP (both producer and exchange patterns).
For producer streams, use __iter__() — yields batches from batched
responses and follows continuation tokens transparently.
For exchange streams, use exchange() — sends an input batch and
receives an output batch.
Supports context manager protocol for convenience.
Initialize with HTTP client, method details, and initial state.
Source code in vgi_rpc/http/_client.py
typed_header
¶
Return the stream header narrowed to the expected type.
| PARAMETER | DESCRIPTION |
|---|---|
header_type
|
The expected header dataclass type.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
H
|
The header, typed as header_type. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the header is |
Source code in vgi_rpc/http/_client.py
exchange
¶
exchange(input_batch: AnnotatedBatch) -> AnnotatedBatch
Send an input batch and receive the output batch.
| PARAMETER | DESCRIPTION |
|---|---|
input_batch
|
The input batch to send.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnnotatedBatch
|
The output batch from the server. |
| RAISES | DESCRIPTION |
|---|---|
RpcError
|
If the server reports an error or the stream has finished. |
Source code in vgi_rpc/http/_client.py
__iter__
¶
__iter__() -> Iterator[AnnotatedBatch]
Iterate over output batches from a producer stream.
Yields pre-loaded batches from init, then follows continuation tokens.
Source code in vgi_rpc/http/_client.py
close
¶
__enter__
¶
__enter__() -> HttpStreamSession
__exit__
¶
Testing¶
make_sync_client
¶
make_sync_client(
server: RpcServer,
*,
prefix: str = "",
signing_key: bytes | None = None,
max_stream_response_bytes: int | None = None,
max_request_bytes: int | None = None,
authenticate: (
Callable[[Request], AuthContext] | None
) = None,
default_headers: dict[str, str] | None = None,
upload_url_provider: UploadUrlProvider | None = None,
max_upload_bytes: int | None = None,
otel_config: object | None = None,
sentry_config: object | None = None,
token_ttl: int = 3600,
compression_level: int | None = 3,
enable_not_found_page: bool = True,
enable_landing_page: bool = True,
enable_describe_page: bool = True,
repo_url: str | None = None,
oauth_resource_metadata: (
OAuthResourceMetadata | None
) = None
) -> _SyncTestClient
Create a synchronous test client for an RpcServer.
Uses falcon.testing.TestClient internally — no real HTTP server needed.
| PARAMETER | DESCRIPTION |
|---|---|
server
|
The RpcServer to test.
TYPE:
|
prefix
|
URL prefix for RPC endpoints (default
TYPE:
|
signing_key
|
HMAC key for signing state tokens (see
TYPE:
|
max_stream_response_bytes
|
See
TYPE:
|
max_request_bytes
|
See
TYPE:
|
authenticate
|
See
TYPE:
|
default_headers
|
Headers merged into every request (e.g. auth tokens).
TYPE:
|
upload_url_provider
|
See
TYPE:
|
max_upload_bytes
|
See
TYPE:
|
otel_config
|
See
TYPE:
|
sentry_config
|
See
TYPE:
|
token_ttl
|
See
TYPE:
|
compression_level
|
See
TYPE:
|
enable_not_found_page
|
See
TYPE:
|
enable_landing_page
|
See
TYPE:
|
enable_describe_page
|
See
TYPE:
|
repo_url
|
See
TYPE:
|
oauth_resource_metadata
|
See
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
_SyncTestClient
|
A sync client that can be passed to |