Skip to main content

A Python API client for interacting with PostgREST applications.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypgrest-dev-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypgrest_dev-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file pypgrest-dev-0.1.0.tar.gz.

File metadata

  • Download URL: pypgrest-dev-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for pypgrest-dev-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9444378953e5ec01387693aa498845619799781ba41b931a60b20924467bdae2
MD5 fcc104e2a36ad43514e4d56a767dfa01
BLAKE2b-256 60c3be4c213ea6f0683f4bc05c3378df47c3ea42ad2d793f8c1cc05c90977781

See more details on using hashes here.

File details

Details for the file pypgrest_dev-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pypgrest_dev-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for pypgrest_dev-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 baa51b1a2d28f6a1cb580e4d50a2f6f3768ea999a0e3d3648bdd5876eea445fc
MD5 caffae7100f067aec2562695986609d1
BLAKE2b-256 ffd3bdfa7d8fc471d0b950f99b833575d5847b8a10bf52113e1a8829ec75b8b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page