pydantable.fastapi¶
Optional FastAPI integration (install pydantable[fastapi]). See the Golden path.
pydantable.fastapi
¶
Optional FastAPI helpers (install pydantable[fastapi]).
import pydantable does not require FastAPI; import this submodule when you use
FastAPI in your service.
ColumnLengthMismatchError
¶
Bases: PydantableUserError
Raised when per-column list lengths disagree for a rectangular table mapping.
Typical cause: constructing a dict[str, list] or equivalent where one column
has a different row count than the others.
Source code in python/pydantable/errors.py
PydantableUserError
¶
Bases: ValueError
Base class for predictable validation and contract failures.
Subclasses :exc:ValueError so except ValueError still matches; use this
base or a concrete subclass when you need to distinguish pydantable errors from
other :exc:ValueError sources.
Source code in python/pydantable/errors.py
IngestValidationErrorDetail
¶
Bases: BaseModel
Top-level error payload for a batch ingest operation.
Source code in python/pydantable/ingest_errors.py
ingest_error_response
¶
Return a structured JSON response describing batch ingest validation failures.
Intended for use with ignore_errors=True and on_validation_errors=... where you
accept partial success but need a stable error payload for clients.
Source code in python/pydantable/fastapi/__init__.py
executor_lifespan
async
¶
Attach a thread pool executor to app.state.executor.
Use with FastAPI's lifespan so acollect(executor=...) and
pydantable.io helpers can share a dedicated pool instead of the default
asyncio thread pool.
Example::
@asynccontextmanager
async def lifespan(app: FastAPI):
async with executor_lifespan(app, max_workers=4):
yield
app = FastAPI(lifespan=lifespan)
Source code in python/pydantable/fastapi/__init__.py
ndjson_chunk_bytes
async
¶
Yield dict[str, list] chunks as UTF-8 NDJSON lines (JSON + newline).
Use with the async iterator from :meth:pydantable.dataframe.DataFrame.astream
when building a custom :class:starlette.responses.StreamingResponse.
Source code in python/pydantable/fastapi/__init__.py
ndjson_streaming_response
¶
Wrap an astream() iterator as a NDJSON :class:StreamingResponse.
Each chunk is JSON-encoded on its own line (common for streaming columnar dicts to HTTP clients).
Source code in python/pydantable/fastapi/__init__.py
get_executor
¶
Return app.state.executor when set by :func:executor_lifespan.
Use with Depends(get_executor) and pass the result to
acollect(executor=...).
Source code in python/pydantable/fastapi/__init__.py
register_exception_handlers
¶
Register HTTP-friendly handlers for common pydantable / Pydantic errors.
- :exc:
~pydantable.MissingRustExtensionError→ 503 (native extension missing). - :exc:
~pydantable.errors.ColumnLengthMismatchError→ 400 withdetailstring. - :exc:
pydantic.ValidationError→ 422 withdetailas Pydantic's error list.
Inbound request body validation is usually handled by FastAPI as
:exc:fastapi.exceptions.RequestValidationError (422) before your route runs.
This handler covers :exc:~pydantic.ValidationError raised inside handlers (for
example manual model_validate). Other :exc:ValueError subclasses from the
engine are not handled here — map those in your routes if needed.
Idempotent for duplicate registration: re-calling on the same app replaces handlers for the same exception types (Starlette/FastAPI behavior).