High-level HTTP clients for Python.
Project description
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
Clientobject 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clients-1.5.1.tar.gz.
File metadata
- Download URL: clients-1.5.1.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b609e585074e5d783812caa2f51958db391c41cebc84eb048d8c370b1cc2fad
|
|
| MD5 |
48da5eb0e552767ba749c5131b38bd8d
|
|
| BLAKE2b-256 |
1404e155db4558fd8f1fbc6e3baf363ea50c555df836ebe27cccd7d2492b4950
|
Provenance
The following attestation bundles were made for clients-1.5.1.tar.gz:
Publisher:
release.yml on coady/clients
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clients-1.5.1.tar.gz -
Subject digest:
4b609e585074e5d783812caa2f51958db391c41cebc84eb048d8c370b1cc2fad - Sigstore transparency entry: 646893372
- Sigstore integration time:
-
Permalink:
coady/clients@254a1e3d5370f007d3a90da9e535a4153455cfc6 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/coady
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@254a1e3d5370f007d3a90da9e535a4153455cfc6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file clients-1.5.1-py3-none-any.whl.
File metadata
- Download URL: clients-1.5.1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7132854c959c81fc7d86d65e5be2919bd59c04ef49aaa22d9ac0121f45300740
|
|
| MD5 |
d0c4b9c12c73471abeb40282032214a4
|
|
| BLAKE2b-256 |
08c851d266abc2256044f9fc756f058a83d251f855b783fb464c8f2cc1d1c5ea
|
Provenance
The following attestation bundles were made for clients-1.5.1-py3-none-any.whl:
Publisher:
release.yml on coady/clients
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clients-1.5.1-py3-none-any.whl -
Subject digest:
7132854c959c81fc7d86d65e5be2919bd59c04ef49aaa22d9ac0121f45300740 - Sigstore transparency entry: 646893375
- Sigstore integration time:
-
Permalink:
coady/clients@254a1e3d5370f007d3a90da9e535a4153455cfc6 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/coady
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@254a1e3d5370f007d3a90da9e535a4153455cfc6 -
Trigger Event:
push
-
Statement type: