Metadata-Version: 2.4
Name: postgrest
Version: 3.0.0a2
Summary: PostgREST client for Python. This library provides an ORM interface to PostgREST.
Author: Lương Quang Mạnh, Joel Lee, Anand, Oliver Rice, Andrew Smith
Author-email: Lương Quang Mạnh <luongquangmanh85@gmail.com>, Joel Lee <joel@joellee.org>, Andrew Smith <a.smith@silentworks.co.uk>
License-Expression: MIT
License-File: LICENSE
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Operating System :: OS Independent
Requires-Dist: pydantic>=2.12,<3
Requires-Dist: yarl>=1.20.1
Requires-Dist: supabase-utils==3.0.0a2
Requires-Dist: typing-extensions>=4.12.0
Maintainer: Leonardo Santiago
Maintainer-email: Leonardo Santiago <leonardo.santiago@supabase.io>
Requires-Python: >=3.12
Project-URL: homepage, https://github.com/supabase/supabase-py/tree/main/src/postgrest
Project-URL: repository, https://github.com/supabase/supabase-py
Project-URL: documentation, https://supabase.com/docs/reference/python/select
Project-URL: changelog, https://github.com/supabase/supabase-py/tree/main/CHANGELOG.md
Description-Content-Type: text/markdown

# postgrest

[PostgREST](https://postgrest.org) client for Python.

## Installation

Needs Python 3.12 or newer and an HTTP client adapter, such as httpx:

```sh
uv add postgrest "supabase_utils[httpx]"
# or
pip install postgrest "supabase_utils[httpx]"
```

## Supabase Service Compatibility

Only the
[latest PostgREST release](https://github.com/PostgREST/postgrest/releases) is
guaranteed to work. Older releases are supported on a best-effort basis. If you
self-host, upgrade PostgREST when you upgrade this package.

## Usage

The client takes the URL of PostgREST and the HTTP session to send requests
with. Leaving the context manager closes the session:

```python
import asyncio

from httpx import AsyncClient
from postgrest import AsyncPostgrestClient
from supabase_utils.http.adapters.httpx import AsyncHttpxSession


async def main() -> None:
    async with AsyncPostgrestClient(
        "http://127.0.0.1:56321/rest/v1", AsyncHttpxSession(AsyncClient())
    ) as client:
        response = await client.from_("countries").select("*").execute()
        print(response.data)


asyncio.run(main())
```

`SyncPostgrestClient` with an `HttpxSession` works the same way without `await`.
The examples below use the async `client`.

### Insert, select, update and delete

```python
countries = client.from_("countries")
await countries.insert({"name": "Việt Nam", "capital": "Hà Nội"}).execute()
response = await countries.select("id", "name").execute()
await countries.update({"capital": "Hà Nội"}).eq("name", "Việt Nam").execute()
await countries.delete().eq("name", "Việt Nam").execute()
```

An update or delete without a filter raises `ValueError` before anything is
sent. Call `all()` to affect every row on purpose:

```python
await client.from_("countries").update({"visited": False}).all().execute()
```

### Reuse a query

Builder methods return a new query and leave the original unchanged, so one base
query can branch into several requests:

```python
asian = client.from_("countries").select("id", "name").eq("continent", "Asia")
large = await asian.gte("population", 100_000_000).execute()
small = await asian.lt("population", 1_000_000).execute()
```

### Call a database function

```python
await client.rpc("foobar", {"arg1": "value1", "arg2": "value2"}).execute()
```

## Local development

Start a local PostgREST with the
[Supabase CLI](https://supabase.com/docs/guides/local-development/cli/getting-started).
It listens on <http://127.0.0.1:56321/rest/v1>:

```sh
supabase --workdir infra start
```
