Skip to main content

Universal REST API Client

Build Status codecov PyPI version

Features

This library is a small REST API client with the following features:

  • Url builder - allows you to build a url by natively calling the client's attributes
  • HTTP requests - a thin wrapper around the requests library that allows full control of the HTTP requests.

Installation

pip install universal-api-client

Usage

Initialising the client

from universal_api_client import Client
swapi_client = Client(base_url='https://swapi.co/api/')

Building a URL

The url builder is part of the request (APIRequest) attribute of the client.

swapi_client.request.people # <universal_api_client.request.APIRequest at 0x1093c3eb8>
swapi_client.request.people.url # 'https://swapi.co/api/people/'
swapi_client.request.people(identifier=1).url # 'https://swapi.co/api/people/1/'
swapi_client.request.people(identifier='1').url # 'https://swapi.co/api/people/1/'

Making a request

The requests are made by the already built APIRequest object. The method call returns the appropriate method call from the requests library.

response = swapi_client.request.people(identifier='1').get() # <Response [200]>
print(response.status_code) # 200

Authentication

The library allows the use of the requests authentication classes (request.auth).

There are 2 ways to add authentication:

  1. When initializing the client.
from requests.auth import HTTPBasicAuth

swapi_client = Client(base_url='https://swapi.co/api/', auth=HTTPBasicAuth('user', 'pass'))
  1. When performing the request (overrides the authentication set in the client).
from requests.auth import HTTPBasicAuth

swapi_client.request.people.get(auth=HTTPBasicAuth('user', 'pass'))

Trailing slash

Some API urls require (or not) a trailing slash at the end of the URL. This can be controlled by the trailing_slash flag when creating the client:

from universal_api_client import Client
swapi_client = Client(base_url='https://swapi.co/api/', trailing_slash=False)

swapi_client.request.people(identifier='1').url # 'https://swapi.co/api/people/1'

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Metadata

Release files for universal-api-client 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 universal-api-client 0.2.0
File Size Uploaded Provenance
universal-api-client-0.2.0.tar.gz 3.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for universal-api-client 0.2.0
File Interpreter ABI Platform
universal_api_client-0.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 9.1 kB

Release files / universal-api-client-0.2.0.tar.gz

Download URL universal-api-client-0.2.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
64a83dc9582dff1d9445dd7c4999c3e73666e019742fc01799ed3f283b1b1386
BLAKE2b-256 checksum
How to use checksums
98f523016a567dbd8589085a7a489d32e00c69603db4f33d67d23e6d13201fed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release files / universal_api_client-0.2.0-py2.py3-none-any.whl

Download URL universal_api_client-0.2.0-py2.py3-none-any.whl
Size 5.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
669f84d58583fda630835d92caf967b56dbb6e1e98123b7c21fd0cb80855e5ca
BLAKE2b-256 checksum
How to use checksums
8fe229a006bb693dcac0abe29a046c3b1543e14bd0e9264f105ab5ea51d02c45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Security for universal-api-client 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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