Skip to main content

High-level HTTP clients for Python.

Project description

image image image image image image image image image

Clients originally provided requests wrappers to encourage best practices, particularly always using Sessions to connect to the same host or api endpoint. The primary goals were:

  • provide a Client object with a convenient constructor
  • support a base url so that requests can provide a relative path
  • provide the same interface for asyncio

Since then httpx has emerged as the successor to requests, and supports the above features natively. So clients.Client can be replaced with httpx.Client for most use cases. The project will continue to be maintained for additional features, such as the Resource object.

Usage

Typical requests usage is redundant and inefficient, by not taking advantage of connection pooling.

r = requests.get('https://api.github.com/user', headers={'authorization': token})
r = requests.get('https://api.github.com/user/repos', headers={'authorization': token})

Using sessions is the better approach, but more verbose and in practice requires manual url joining.

s = requests.Session()
s.headers['authorization'] = token
r = s.get('https://api.github.com/user')
r = s.get('https://api.github.com/user/repos')

Client

Clients make using sessions easier, with implicit url joining.

client = clients.Client('https://api.github.com/', headers={'authorization': token})
r = client.get('user')
r = client.get('user/repos')

Resource

Resources extend Clients to implicitly handle response content, with proper checking of status_code and content-type.

github = clients.Resource('https://api.github.com/', headers={'authorization': token})
for repo in github.get('user/repos', params={'visibility': 'public'}):
    ...

Resources also implement syntactic support for methods such as getattr and call, providing most of the benefits of custom clients as is.

for repo in github.user.repos(visibility='public'):
    ...

Asynchronous variants of all client types are provided, e.g., AsyncClient. Additional clients for RPC, GraphQL, and proxies also provided.

Installation

% pip install clients

Dependencies

  • httpx

Tests

100% branch coverage.

% pytest [--cov]

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

clients-1.5.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

clients-1.5-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file clients-1.5.tar.gz.

File metadata

  • Download URL: clients-1.5.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for clients-1.5.tar.gz
Algorithm Hash digest
SHA256 845c90539b7c7211dd4ac2fcaecec18ec29dcd03e40a283866c9510f795025b7
MD5 64aa6cec0a6b23b109e57255ad4d2514
BLAKE2b-256 97ac58af351b3a1cd861911e3cebe9708e659b6ed285fb688b323c24857023d6

See more details on using hashes here.

File details

Details for the file clients-1.5-py3-none-any.whl.

File metadata

  • Download URL: clients-1.5-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for clients-1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 36a174fc5247811ea84255f4021a994405975b82b98a1d735d71e3a3da8e6a46
MD5 34294d7037814f52d3e5d73ea75eed48
BLAKE2b-256 8c6627cdbb2d61cea846dfab6f63d0ddad9286369e66ee9c9e2a00c9cf136e12

See more details on using hashes here.

Supported by

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