Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anand2312/pgrest
A Python client library for PostgREST APIs.
https://github.com/anand2312/pgrest
async postgrest python
Last synced: about 1 month ago
JSON representation
A Python client library for PostgREST APIs.
- Host: GitHub
- URL: https://github.com/anand2312/pgrest
- Owner: anand2312
- License: mit
- Created: 2021-10-28T08:03:08.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-01T22:23:29.000Z (over 1 year ago)
- Last Synced: 2024-09-24T05:38:08.512Z (about 1 month ago)
- Topics: async, postgrest, python
- Language: Python
- Homepage: https://anand2312.github.io/pgrest
- Size: 788 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pgrest
Asynchronous PostgREST client for Python. This library provides an ORM interface to PostgREST.
Fork of the supabase community Postgrest Client library for Python.
[Documentation](https://anand2312.github.io/pgrest)
## Getting Started
Before running any queries, you need to initialize the client:
```py
from pgrest import Clientclient = Client("http://localhost:3000") # pass in your postgrest API url
client.auth("bearer token") # pass in your API bearer token
```You can insert new rows...
```py
await client.from_("countries").insert({ "name": "Việt Nam", "capital": "Hà Nội" }).execute()
```
or bulk insert multiple rows in a single query:
```py
rows = [{"name": "India", "capital": "New Delhi"}, {"name": "Japan", "capital": "Tokyo"}]
await client.from_("countries").insert_many(rows).execute()
```
Read rows
```py
r = await client.from_("countries").select("id", "name").execute()
countries = r[0]
```
Or run more complicated filters for your queries!
```py
from pgrest import Column
# you can merge multiple conditions with AND/OR clauses
# | means OR, & means AND
r = await client.from_("countries")
.select("*")
.where((Column("population") >= 10_000_000) & (Column("population") <= 20_000_000) | (Column("name").ilike("%stan")))
.execute()
# this query fetches all countries whose population is between 10 million and 20 million, or whose name ends in `stan`
```## PROJECT TODOS:
- [ ] upsert methods
- [x] AND/OR filtering (v0.7.0)
- [ ] allow users to pass response models?
- [ ] add configuration parameter to text-search functions