Skip to main content

Pypgrest

A Python client for interacting with PostgREST APIs.

Installation

$ pip install pypgrest

Quick start

>>> from pypgrest import Postgrest

>>> client = Postgrest("https://api.tacos.com", token="secretsalsa")

# See postgrest docs for supported query params
>>> params = {
        "select" : "name,tortilla,cost",
        "tortilla" : "is.corn",
        "limit" : 100,
        "order": "name"
    }

# Supported methods are select, insert, update, upsert, and delete
>>> client.select(resource="menu", params=params, pagination=True, headers=None)
# [{ "name" : "al pastor", "tortilla" : "corn", "cost" : "2.01" }, ... ]

>>> payload = [{ "id" : 23, "cost" : "2.25" }, { "id" : 26, "cost" : "1.25" }]

>>> pgrest.upsert(payload)
# [{ "id" : 23, "cost" : "2.25", "name" : "al pastor", ... }, ... ]

# You can inspect the response object at `self.res`:
>>> client.res.status_code
# 201

Headers

The client is initialized with Content-Type=application/json and (if you supply a token) Authorization headers. You can supply additional headers on construction, or per request.

>>> client = Postgrest(
    "https://api.tacos.com",
    token="secretsalsa", 
    headers={"Prefer": "return=representation"}
)

>>> client.headers
# {"Content-Type": 'application/json', 'Authorization': 'Bearer secretsalsa', 'Prefer': 'return=representation'}

>>> client.insert(
    resource="menu",
    data={"id": 5, "name": "barbacoa"},
    headers={"Prefer": "return=headers-only"}
)

Limits and pagination

By default, the client will paginate requests until all records have been retrieved. You can supply a limit param to limit the number of results returned by select.

You can disable pagination with pagination=False, in which case the record limit will be capped by your API's max-rows setting.

Development

We use Github Actions to publish to PyPI. The workflows are defined in .github/workflows.

Any commit/merge to the dev branch will trigger a PyPI publication to the knackpy-dev package. Any release on the master branch will trigger publication to the knackpy package on PyPI. Note that PyPI publications will fail if don’t bump the version number in setup.py.

License

As a work of the City of Austin, this project is in the public domain within the United States.

Additionally, we waive copyright and related rights of the work worldwide through the CC0 1.0 Universal public domain dedication.

Metadata

Release files for pypgrest 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pypgrest 0.2.0
File Size Uploaded
pypgrest-0.2.0.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pypgrest 0.2.0
File Interpreter ABI Platform
pypgrest-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.8 kB

Release files / pypgrest-0.2.0.tar.gz

Download URL pypgrest-0.2.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
017c6a50d49e20f81c24f59068d732961efc24673b5d43644137f00d28111249
BLAKE2b-256 checksum
How to use checksums
1c172bdab61e8125457469b7fb79634b0b4f11cbd657f85ec2c0611d55d59f27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / pypgrest-0.2.0-py3-none-any.whl

Download URL pypgrest-0.2.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81428b76e486755aa7ec6da7b6a55095fce8a8dab387e2bfee10a06f2d096ace
BLAKE2b-256 checksum
How to use checksums
42eea7fb79a3f2c22e67b7e2ec39e551386fa0e8bdfe006529edb9208c114321
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page