Skip to main content

HTTP for lazy, impatient, hubristic humans.

Project description

https://img.shields.io/pypi/v/clients.svg https://img.shields.io/pypi/pyversions/clients.svg https://img.shields.io/pypi/status/clients.svg https://img.shields.io/travis/coady/clients.svg https://img.shields.io/codecov/c/github/coady/clients.svg https://readthedocs.org/projects/clients/badge

Clients provide requests and aiohttp wrappers which encourage best practices, particularly always using Sessions to connect to the same host or api endpoint.

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')

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')

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, without having to define a schema.

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

Being session based, Clients work seamlessly with other requests adapters, such as CacheControl. Asynchronous variants of all client types are provided in Python >=3.5, using aiohttp instead of requests. Additional clients for RPC, GraphQL, and proxies also provided.

Read the documentation.

Installation

$ pip install clients

Dependencies

  • requests >=2.4.2

  • aiohttp (if Python >=3.5)

Tests

100% branch coverage.

$ pytest [--cov]

Changes

0.5

  • AsyncClient default params

  • Remote and AsyncRemote procedure calls

  • Graph and AsyncGraph execute GraphQL queries

  • Proxy and AsyncProxy clients

0.4

  • Asynchronous clients and resources

0.3

  • singleton decorator

0.2

  • Resource attribute upcasts back to a client

  • iter and download implement GET requests with streamed content

  • create implements POST request and returns Location header

  • update implements PATCH request with json params

  • __call__ implements GET request with params

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-0.5.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

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

clients-0.5-py2.py3-none-any.whl (10.3 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: clients-0.5.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for clients-0.5.tar.gz
Algorithm Hash digest
SHA256 d4fbce724b4eca33564bee823aa3cae3e6adcfb52b954f0cb610f444cafe2642
MD5 bae064cc730e4fb6e8f6705d880d383c
BLAKE2b-256 1cb9d40e6cdc506b50cb0307a0c9c1fe8f646f0261c6ef1419254df74bff9d14

See more details on using hashes here.

File details

Details for the file clients-0.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for clients-0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d8584ec6f85544e487d4cbb3c37e85aa4ea927e99b9bc865832a2c1990457a12
MD5 07efe517b9a0914b149e2fa090362b3c
BLAKE2b-256 49f1df01e9eb46ec8d1b91c8dca3dcce00905b2ec1c85735db06fd8c4edb3831

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