-
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
.
-
Notifications
You must be signed in to change notification settings - Fork 0
A minimal example to show how to query a collection asynchronously with Psycopg3 and expose those results behind a FastAPI REST endpoint.
License
chuck-alt-delete/fastapi_psycopg3_example
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
A minimal example to show how to query a collection asynchronously with Psycopg3 and expose those results behind a FastAPI REST endpoint.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published