Skip to main content

webfunction-python

A reference client library for the Web Function (wfn) protocol.

Part of the same reference-client suite as the Ruby gem (https://github.com/webfunction-protocol/webfunction-ruby, the spec author's own implementation), webfunction-go, webfunction-java, and webfunction-csharp.

Install

pip install webfunction

The only runtime dependency is httpx, which is what lets this library offer both a synchronous Client and an async AsyncClient from a single implementation.

Usage

Sync

from webfunction import Client

client = Client.from_package_endpoint("https://api.example.com/package")
result = client.list_items(email="a@example.com")  # dynamic dispatch, no generated code

Async

import asyncio
from webfunction import AsyncClient

async def main():
    client = await AsyncClient.from_package_endpoint("https://api.example.com/package")
    result = await client.list_items(email="a@example.com")

asyncio.run(main())

Pagination

Endpoints that declare the paginated flag return a Page (or AsyncPage):

page = client.list_people()
for person in page:
    ...
if page.has_next:
    page = page.next_page()

Pipelining

If the package declares a pipeline_url, pass pipelined=True to batch several endpoint invocations into a single request. Calls return a Promise instead of executing immediately; index into a promise (promise["id"]) to build a reference to one of its fields before it's resolved.

client = Client.from_package_endpoint(url, pipelined=True)
item = client.list_items(email="a@example.com")
detail = client.get_widget(id=item["id"])  # references item's future "id" field
results = client.pipeline.execute()
print(detail.value)

Errors

All errors are subclasses of WebFunctionError, carrying .code, .message, and .details: BadRequestError, UnexpectedStatusCodeError, JsonParseError, UnresolvedPromiseError.

A note on unknown fields

This library never validates incoming JSON against a strict schema -- model classes only read the keys they know about via plain dict.get(), so an API that adds an undocumented field to its responses (this has happened for real against api.reservepay.com) won't break parsing the way it did for the Java client, which needed an explicit fix to disable strict unknown-field rejection.

Development

pip install -e .
python -m unittest discover tests

Release files for webfunction 0.1.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 webfunction 0.1.0
File Size Uploaded
webfunction-0.1.0.tar.gz 18.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for webfunction 0.1.0
File Interpreter ABI Platform
webfunction-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.2 kB

Release files / webfunction-0.1.0.tar.gz

Download URL webfunction-0.1.0.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
88c857b02cca344baf231d8b7d87f153ec0837a21476009ef6f2d31da51e2c22
BLAKE2b-256 checksum
How to use checksums
ba1d5202a673aeb498ec1f4f0089b8a328f5911c6517c1196156daa72fde25cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / webfunction-0.1.0-py3-none-any.whl

Download URL webfunction-0.1.0-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
672b7ee28d3c87736758c3b1f130970090f4a81df7b5da69156e15e5c948aff1
BLAKE2b-256 checksum
How to use checksums
771bbaa48db909f408e3a18ba6f493963978ec76c288f0954d77ecea8ae75e8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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