Skip to main content

Package handling tokens and URLs

Project description

cwtoken Technical Reference

cwtoken simplifies working with PostgREST APIs by:

  • Automatically handling access token generation
  • Provides a query constructor for URL generation, and a diagnostic mode for debugging
  • Making authenticated GET requests to PostgREST endpoints
  • Providing a CLI for quick testing and usage
  • Including a user-friendly GUI for building and running queries without code

cwapi — API Client

Represents an authenticated connection to the PostgREST API. All queries are created via this object.

Constructor:

client = cwapi( api_token: str, clubcode: str = None, # required if access_token not provided access_token: str = None, base_url: str = "https://atukpostgrest.clubwise.com/" )

Attributes:

  • client.access_token — automatically fetched if not provided
  • client.headers — dict of headers including Authorization
  • client.clubcode — club code used

Methods:

  • client.table(endpoint: str) -> query
    Returns a query constructor object for building endpoint queries. Supports method chaining.

  • client.raw_query(full_query: str) -> RawQuery
    Returns a raw query object for executing a fully specified URL.

query — Table-based Query Constructor

  • Created via client.table(endpoint)
  • Supports chained methods:

q = client.table("member")
.select("member_no", "first_name")
.filters("date_of_birth=gt.1980-01-01")
.order("first_name", desc=True)
.limit(10)

Attributes:

  • client.diagnostic: bool — Enables diagnostic mode for your query. Allows it to identify which part of the input query is malformed upon faliure, set to False by default.

Methods:

  • .select(*columns) — adds columns to select
  • .filters(*filters) — raw PostgREST filter strings
  • .order(*columns, desc=False) — orders results
  • .limit(n) — limits results
  • .fetch() -> pandas.DataFrame — executes query

RawQuery — Direct URL Query

  • Created via client.raw_query(full_query)
  • method:

df = client.raw_query("member?select=first_name&limit=10").fetch()

  • .fetch() -> pandas.DataFrame — executes URL request
  • Bypasses query builder chaining; used for pre-formed URLs

CLI Functions

test_connection()

Pings the API server to check if it's reachable.

Can be run from the CLI:

cwtoken test

cwtoken gui

Launches the graphical interface for building and executing queries.

Run it from the CLI like this:

cwtoken gui

Notes on Usage

  • Queries are always linked to a client.
  • Method chaining is supported for the query object.
  • Both query and RawQuery return pandas.DataFrame on .fetch().
  • RawQuery can be used for fully constructed URLs without using the query builder.

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

cwtoken-0.4.2.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

cwtoken-0.4.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file cwtoken-0.4.2.tar.gz.

File metadata

  • Download URL: cwtoken-0.4.2.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cwtoken-0.4.2.tar.gz
Algorithm Hash digest
SHA256 6cd6222ff30230fa284fe529b3e702ff98a3703481a239d9aa297c579dd2e89f
MD5 bfb53a61a59835695907db72b5cc8c6e
BLAKE2b-256 76b9492bee90f8de9324133c0ef4b806a585c1fd8daec561a64a8e1426fab61b

See more details on using hashes here.

File details

Details for the file cwtoken-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: cwtoken-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cwtoken-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 183e013992cc1d31d5eb56f40a39d2bc2cea09abf016e226f8c2ac0319bda8dc
MD5 0ea57cb85f50ba651666d10a5214dd86
BLAKE2b-256 f97d512a9b0b06865060f73b76ec9668584cffbe9e6e4d81b0c671921f03315d

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