-
Inspect the code.
-
Fill out your database connection details as environment variables in a file called
.env
. Here is an example:export MZ_HOST=<id>.<region>.aws.materialize.cloud export [email protected] export MZ_PASSWORD=<app password> export MZ_PORT=6875 export MZ_DB=materialize export MZ_CLUSTER=chuck export MZ_SCHEMA=public export MZ_TRANSACTION_ISOLATION=serializable
-
Install dependencies.
python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt
-
Run the FastAPI server.
uvicorn main:app
-
Access the endpoint.
curl -L localhost:8000/my_data
{"data":[{"a":0,"b":0},{"a":0,"b":1},{"a":1,"b":0},{"a":1,"b":1},{"a":2,"b":0}]}
This assumes you have a Postgres compatible database with a collection called
my_collection
with integer columnsa
andb
.
chuck-alt-delete / fastapi_psycopg3_example Goto Github PK
View Code? Open in Web Editor NEWA minimal example to show how to query a collection asynchronously with Psycopg3 and expose those results behind a FastAPI REST endpoint.
License: MIT License