Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs: add rtd config * chore: move to the postgrest namespace * chore: move constants to its own file * chore: pass headers/params down builders We were earlier modifying session.headers/session.params for every query. Instead of this we follow what postgrest-js does and add headers and params as arguments to the query builders, and pass them down the chain of builders, and finally pass it to the execute method. * docs: add examples * fix: order of filters in examples * docs: add example for closing the client
- Loading branch information
Showing
39 changed files
with
435 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: 2 | ||
|
||
build: | ||
os: ubuntu-20.04 | ||
tools: | ||
python: "3.9" | ||
|
||
python: | ||
install: | ||
- requirements: docs/requirements.txt | ||
|
||
|
||
- method: pip | ||
path: . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Exceptions | ||
========== | ||
|
||
.. autoexception:: postgrest_py.APIError | ||
.. autoexception:: postgrest.APIError | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Responses | ||
========= | ||
|
||
Once a query is run, the postgrest_py parses the server's response into an APIResponse object. | ||
Once a query is run, the library parses the server's response into an APIResponse object. | ||
|
||
.. autoclass:: postgrest_py.APIResponse | ||
.. autoclass:: postgrest.APIResponse | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
Getting Started | ||
=============== | ||
|
||
We connect to the API and authenticate, and fetch some data. | ||
|
||
.. code-block:: python | ||
:linenos: | ||
import asyncio | ||
from postgrest import AsyncPostgrestClient | ||
async def main(): | ||
async with AsyncPostgrestClient("http://localhost:3000") as client: | ||
client.auth("Bearer <token>") | ||
r = await client.from_("countries").select("*").execute() | ||
countries = r.data | ||
asyncio.run(main()) | ||
**CRUD** | ||
|
||
.. code-block:: python | ||
await client.from_("countries").insert({ "name": "Việt Nam", "capital": "Hà Nội" }).execute() | ||
.. code-block:: python | ||
r = await client.from_("countries").select("id", "name").execute() | ||
countries = r.data | ||
.. code-block:: python | ||
await client.from_("countries").update({"capital": "Hà Nội"}).eq("name", "Việt Nam").execute() | ||
.. code-block:: python | ||
await client.from_("countries").delete().eq("name", "Việt Nam").execute() | ||
**Calling RPCs** | ||
|
||
.. code-block:: python | ||
await client.rpc("foo").execute() | ||
.. code-block:: python | ||
await client.rpc("bar", {"arg1": "value1", "arg2": "value2"}).execute() | ||
**Closing the connection** | ||
|
||
Once you have finished running your queries, close the connection: | ||
|
||
.. code-block:: python | ||
await client.aclose() | ||
You can also use the client with a context manager, which will close the client for you. | ||
|
||
.. code-block:: python | ||
async with AsyncPostgrestClient("url") as client: | ||
# run queries | ||
# the client is closed when the async with block ends |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
Examples | ||
======== | ||
|
||
Stay tuned! Examples are coming soon. | ||
.. note:: | ||
The library offers both synchronous and asynchronous clients. In the examples, we use the | ||
async client. However, they should work the same for the sync client as well. | ||
|
||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:caption: More examples: | ||
|
||
Basic Queries <basic_queries> | ||
Logging Requests <logging> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Logging Requests | ||
================ | ||
|
||
While debugging, you might want to see the API requests that are being sent for every query. | ||
To do this, just set the logging level to "DEBUG": | ||
|
||
.. code-block:: python | ||
:linenos: | ||
from logging import basicConfig, DEBUG | ||
from postgrest import SyncPostgrestClient | ||
basicConfig(level=DEBUG) | ||
client = SyncPostgrestClient(...) | ||
client.from_("test").select("*").eq("a", "b").execute() | ||
client.from_("test").select("*").eq("foo", "bar").eq("baz", "spam").execute() | ||
Output: | ||
|
||
.. code-block:: | ||
DEBUG:httpx._client:HTTP Request: GET https://<URL>/rest/v1/test?select=%2A&a=eq.b "HTTP/1.1 200 OK" | ||
DEBUG:httpx._client:HTTP Request: GET https://<URL>/rest/v1/test?select=%2A&foo=eq.bar&baz=eq.spam "HTTP/1.1 200 OK" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
furo >= 2022.4.7 | ||
Sphinx == 4.3.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.