Skip to main content

API client that automatically handles token refresh

Project description

OpenRelik API Client

This Python package provides a simple API client (APIClient) that automatically handles token refresh on 401 (Unauthorized) responses.

  • Automatic token refresh: Seamlessly refreshes expired access tokens using a refresh token.
  • Easy-to-use interface: Simple methods for common HTTP requests (GET, POST, PUT, DELETE).
  • Customizable: Allows you to specify the API server URL, API key, and API version.

Installation

pip install openrelik-api-client

Example:

 import os
 from openrelik_api_client.api_client import APIClient

 # Initialize the API client
 api_server_url = "http://localhost:8710"

 # API key from environment variable
 api_key = os.getenv("OPENRELIK_API_KEY")

 # Create the API client. It will handle token refreshes automatically.
 api_client = APIClient(api_server_url, api_key)

 # Example GET request
 response = api_client.get("/users/me/")
 print(response.json())

How it works:

The APIClient utilizes a custom session class (TokenRefreshSession) that intercepts requests and checks for 401 responses. If a 401 response is encountered, it automatically attempts to refresh the access token using the provided refresh token. If the refresh is successful, the original request is retried with the new access token.

Obligatory Fine Print

This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.

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

openrelik_api_client-0.2.4.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

openrelik_api_client-0.2.4-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file openrelik_api_client-0.2.4.tar.gz.

File metadata

  • Download URL: openrelik_api_client-0.2.4.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for openrelik_api_client-0.2.4.tar.gz
Algorithm Hash digest
SHA256 a908b761514c9370d0b99e9d331825b5ec67a2f739068e7d8f2b8515a54bd9ff
MD5 519eea7fe5a44a25ed3757bf09c060f2
BLAKE2b-256 bea11e5109e9559b4fe65a8c46df646e8d100d5cc5aadba44f303d5a015fe42f

See more details on using hashes here.

Provenance

The following attestation bundles were made for openrelik_api_client-0.2.4.tar.gz:

Publisher: publish-pypi.yml on openrelik/openrelik-api-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openrelik_api_client-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for openrelik_api_client-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 24e4f0a4d1853469986f4121cd8c35410fc729f1898ddc1c1f691124b00506b3
MD5 f83d6f6d632d557e7b9b8e98bec54c4a
BLAKE2b-256 7717b7191ccfd70d3c0e13ddabe540b955f84c28a7389bbd31caa4a946012712

See more details on using hashes here.

Provenance

The following attestation bundles were made for openrelik_api_client-0.2.4-py3-none-any.whl:

Publisher: publish-pypi.yml on openrelik/openrelik-api-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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