Schema-driven REST API simulation with FastAPI, Pydantic, and Polyfactory
Project description
Semblance
Schema-driven REST API simulation using FastAPI, Pydantic, and Polyfactory.
Define API behaviour with schemas and dependency metadata—no endpoint logic required.
Install
pip install semblance
Requires Python 3.10+.
Quick start
from datetime import date, datetime
from typing import Annotated
from pydantic import BaseModel
from semblance import DateRangeFrom, FromInput, SemblanceAPI
class UserQuery(BaseModel):
name: str = "alice"
start_date: date = date(2020, 1, 1)
end_date: date = date(2025, 12, 31)
class User(BaseModel):
name: Annotated[str, FromInput("name")]
created_at: Annotated[
datetime,
DateRangeFrom("start_date", "end_date"),
]
api = SemblanceAPI()
@api.get("/users", input=UserQuery, output=list[User])
def users():
pass
app = api.as_fastapi()
Run with uvicorn app:app and call GET /users?name=alice&start_date=2024-01-01&end_date=2024-12-31. Responses are generated from your output model, with name bound from the query and created_at random in the date range.
Testing
from semblance import SemblanceAPI, test_client
# Build app (register endpoints as above)
app = api.as_fastapi()
client = test_client(app)
r = client.get("/users?name=testuser")
assert r.status_code == 200
data = r.json()
assert all(u["name"] == "testuser" for u in data)
Phase 1 (MVP) status
- SemblanceAPI core
- GET endpoints with query parameter inputs
- Single and list outputs
FromInputandDateRangeFromlinks- Polyfactory integration and FastAPI app export
- Basic pytest client (
semblance.test_client(app))
See docs/semblance_planning_and_roadmap.md for full roadmap.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file semblance-0.1.0.tar.gz.
File metadata
- Download URL: semblance-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1569dff1a4a6c5505d25f01f1daaaee3eea9bb84de63c56c86819a752c8594a3
|
|
| MD5 |
497b6149c3bd8716af8054f537c4d536
|
|
| BLAKE2b-256 |
a3fbf3774e20a43fab67ed547853c0d484f60d77d2850b993d5e3ff73174406d
|
File details
Details for the file semblance-0.1.0-py3-none-any.whl.
File metadata
- Download URL: semblance-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48bd919a14b94d24618b48c516bc4d1c73fc5777635ef23ef6957ed994ad6bbe
|
|
| MD5 |
3106d4f99ebcceafaeda0a0cb2e9a0d3
|
|
| BLAKE2b-256 |
6a2dd420bf755f3f219ca01046446e75631e15a09aec10d1fa0f3caefadef773
|