wiltech-labs-rest
The response-building core for Wiltech FastAPI apps: the typed
_data / _metadata / _metaLinks / _messages envelope, HATEOAS-style
links, field metadata and UTC date formatting, as described in
docs/PYTHON_APP_CONVENTIONS.md.
It's the server side of @wiltech-labs/ngx-api-client,
which reads these envelopes in the Angular apps.
Depends only on pydantic (no FastAPI import), so it's usable from any layer.
Install
Published on PyPI. In the consuming app:
uv add wiltech-labs-rest # adds "wiltech-labs-rest>=x.y.z" to pyproject.toml + uv.lock
Upgrade later with uv lock --upgrade-package wiltech-labs-rest && uv sync.
Docker builds and Cloudflare Workers (pywrangler) download it from PyPI like any other
dependency — it's pure Python, depending only on pydantic.
Usage
# todos/schemas.py
from datetime import datetime
from pydantic import BaseModel, field_serializer
from wiltech_labs_rest import ApiResponse, FieldMetadata, LinkedResource, format_utc_datetime
class TodoDTO(LinkedResource):
id: str
title: str
state: TodoState
created_date: datetime
@field_serializer("created_date")
def serialize_created_date(self, value: datetime) -> str:
return format_utc_datetime(value)
class TodoMetadata(BaseModel):
id: FieldMetadata
title: FieldMetadata
state: FieldMetadata
TodoResponse = ApiResponse[TodoDTO, TodoMetadata]
TodoListResponse = ApiResponse[list[TodoDTO], TodoMetadata]
# todos/todo_service.py
from wiltech_labs_rest import API_PREFIX, FieldMetadata, Link, choice_field
class TodoService:
@staticmethod
def build_links(todo_id: str) -> dict[str, Link]:
url = f"{API_PREFIX}/todos/{todo_id}"
return {
LINK_SELF: Link(href=url),
LINK_UPDATE_TODO: Link(href=url, method="PUT"),
}
def build_metadata(self, todo: TodoDTO) -> TodoMetadata:
return TodoMetadata(
id=FieldMetadata(readOnly=True, hidden=True),
title=FieldMetadata(mandatory=True),
state=choice_field(TodoState), # every enum member as {id, value}
)
def build_response(self, todo: TodoDTO) -> TodoResponse:
return TodoResponse.of(TODO_DATA_NAME, todo, self.build_metadata(todo))
{
"_data": { "todo": { "id": "…", "title": "…", "links": { "self": { "href": "/api/todos/…", "method": "GET" } } } },
"_metadata": { "id": { "readOnly": true, "hidden": true }, "state": { "mandatory": true, "values": [ … ] } },
"_metaLinks": {},
"_messages": []
}
Public API
Everything is imported from wiltech_labs_rest:
| Name | What it is |
|---|---|
ApiResponse[DataT, MetadataT] |
The envelope. Build with ApiResponse.of(data_name, data, metadata, meta_links=None, messages=None). |
API_PREFIX |
"/api" — the prefix every router is mounted under; use it when building hrefs. |
Link |
{href, method="GET"} |
LinkedResource |
DTO base class adding links: dict[str, Link] |
FieldMetadata |
readOnly / hidden / mandatory / values; unset flags are left out of the JSON |
EmbeddedRef |
{id, value} — an option in values, or an embedded reference |
choice_field(enum) |
Mandatory FieldMetadata whose values are every member of the enum |
Message, MessageType |
One _messages entry: INFO / WARNING / ERROR / SUCCESS |
format_utc_datetime(value) |
datetime or ISO string → YYYY-MM-DDTHH:MM:SSZ |
Development, building and publishing
See docs/PUBLISHING.md
for local development, building, and the PyPI release steps.
Quick version, from the repo root:
uv sync
uv run --package wiltech-labs-rest pytest packages/rest
cd packages/rest
uv version --bump patch # or minor / major
uv build # -> ../../dist/
uv publish ../../dist/wiltech_labs_rest-<version>*
Metadata
Release files for wiltech-labs-rest 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wiltech_labs_rest-0.1.0.tar.gz | 7.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wiltech_labs_rest-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.4 kB
Release files / wiltech_labs_rest-0.1.0.tar.gz
| Download URL | wiltech_labs_rest-0.1.0.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a2e1247527543f47f02d3ecf7be9e511e42581ba9d7631f585ca67f5c9b06f4d
|
|
BLAKE2b-256 checksum How to use checksums |
3e9745cdfa11c362f3463952344e20748ec4572f4436e6567abc26c8a729769a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / wiltech_labs_rest-0.1.0-py3-none-any.whl
| Download URL | wiltech_labs_rest-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a95c060c6926a6a2da292be11815d944ed24e496eac6da85a97fd93306375f78
|
|
BLAKE2b-256 checksum How to use checksums |
722a62e5393c578e54894d27c0d210d2929272d5fb6d317b16e3ddc1442bb194
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|