clients


Nameclients JSON
Version 1.5.1 PyPI version JSON
download
home_pageNone
SummaryHigh-level HTTP clients for Python.
upload_time2025-10-27 23:26:41
maintainerNone
docs_urlhttps://pythonhosted.org/clients/
authorNone
requires_python>=3.10
licenseNone
keywords requests sessions responses resources asyncio
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![image](https://img.shields.io/pypi/v/clients.svg)](https://pypi.org/project/clients/)
![image](https://img.shields.io/pypi/pyversions/clients.svg)
[![image](https://pepy.tech/badge/clients)](https://pepy.tech/project/clients)
![image](https://img.shields.io/pypi/status/clients.svg)
[![build](https://github.com/coady/clients/actions/workflows/build.yml/badge.svg)](https://github.com/coady/clients/actions/workflows/build.yml)
[![image](https://codecov.io/gh/coady/clients/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/clients/)
[![CodeQL](https://github.com/coady/clients/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/coady/clients/actions/workflows/github-code-scanning/codeql)
[![image](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![ty](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ty/main/assets/badge/v0.json)](https://github.com/astral-sh/ty)

Clients originally provided [requests](https://python-requests.org) 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](https://www.encode.io/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.

```python
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.

```python
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.

```python
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.

```python
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.

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

Asynchronous variants of all client types are provided, e.g., `AsyncClient`. Additional clients for [RPC](https://en.wikipedia.org/wiki/Remote_procedure_call), [GraphQL](https://graphql.org), and proxies also provided.

## Installation
```console
pip install clients
```

## Dependencies
* httpx

## Tests
100% branch coverage.
```console
pytest [--cov]
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "clients",
    "maintainer": null,
    "docs_url": "https://pythonhosted.org/clients/",
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "requests, sessions, responses, resources, asyncio",
    "author": null,
    "author_email": "Aric Coady <aric.coady@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/14/04/e155db4558fd8f1fbc6e3baf363ea50c555df836ebe27cccd7d2492b4950/clients-1.5.1.tar.gz",
    "platform": null,
    "description": "[![image](https://img.shields.io/pypi/v/clients.svg)](https://pypi.org/project/clients/)\n![image](https://img.shields.io/pypi/pyversions/clients.svg)\n[![image](https://pepy.tech/badge/clients)](https://pepy.tech/project/clients)\n![image](https://img.shields.io/pypi/status/clients.svg)\n[![build](https://github.com/coady/clients/actions/workflows/build.yml/badge.svg)](https://github.com/coady/clients/actions/workflows/build.yml)\n[![image](https://codecov.io/gh/coady/clients/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/clients/)\n[![CodeQL](https://github.com/coady/clients/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/coady/clients/actions/workflows/github-code-scanning/codeql)\n[![image](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![ty](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ty/main/assets/badge/v0.json)](https://github.com/astral-sh/ty)\n\nClients originally provided [requests](https://python-requests.org) wrappers to encourage best practices, particularly always using Sessions to connect to the same host or api endpoint. The primary goals were:\n* provide a `Client` object with a convenient constructor\n* support a base url so that requests can provide a relative path\n* provide the same interface for asyncio\n\nSince then [httpx](https://www.encode.io/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.\n\n## Usage\nTypical `requests` usage is redundant and inefficient, by not taking advantage of connection pooling.\n\n```python\nr = requests.get('https://api.github.com/user', headers={'authorization': token})\nr = requests.get('https://api.github.com/user/repos', headers={'authorization': token})\n```\n\nUsing sessions is the better approach, but more verbose and in practice requires manual url joining.\n\n```python\ns = requests.Session()\ns.headers['authorization'] = token\nr = s.get('https://api.github.com/user')\nr = s.get('https://api.github.com/user/repos')\n```\n\n### Client\nClients make using sessions easier, with implicit url joining.\n\n```python\nclient = clients.Client('https://api.github.com/', headers={'authorization': token})\nr = client.get('user')\nr = client.get('user/repos')\n```\n\n### Resource\nResources extend Clients to implicitly handle response content, with proper checking of status_code and content-type.\n\n```python\ngithub = clients.Resource('https://api.github.com/', headers={'authorization': token})\nfor repo in github.get('user/repos', params={'visibility': 'public'}):\n    ...\n```\n\nResources also implement syntactic support for methods such as __getattr__ and __call__, providing most of the benefits of custom clients as is.\n\n```python\nfor repo in github.user.repos(visibility='public'):\n    ...\n```\n\nAsynchronous variants of all client types are provided, e.g., `AsyncClient`. Additional clients for [RPC](https://en.wikipedia.org/wiki/Remote_procedure_call), [GraphQL](https://graphql.org), and proxies also provided.\n\n## Installation\n```console\npip install clients\n```\n\n## Dependencies\n* httpx\n\n## Tests\n100% branch coverage.\n```console\npytest [--cov]\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "High-level HTTP clients for Python.",
    "version": "1.5.1",
    "project_urls": {
        "Changelog": "https://github.com/coady/clients/blob/main/CHANGELOG.md",
        "Documentation": "https://coady.github.io/clients",
        "Homepage": "https://github.com/coady/clients",
        "Issues": "https://github.com/coady/clients/issues"
    },
    "split_keywords": [
        "requests",
        " sessions",
        " responses",
        " resources",
        " asyncio"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "08c851d266abc2256044f9fc756f058a83d251f855b783fb464c8f2cc1d1c5ea",
                "md5": "d0c4b9c12c73471abeb40282032214a4",
                "sha256": "7132854c959c81fc7d86d65e5be2919bd59c04ef49aaa22d9ac0121f45300740"
            },
            "downloads": -1,
            "filename": "clients-1.5.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d0c4b9c12c73471abeb40282032214a4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 8857,
            "upload_time": "2025-10-27T23:26:40",
            "upload_time_iso_8601": "2025-10-27T23:26:40.195939Z",
            "url": "https://files.pythonhosted.org/packages/08/c8/51d266abc2256044f9fc756f058a83d251f855b783fb464c8f2cc1d1c5ea/clients-1.5.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1404e155db4558fd8f1fbc6e3baf363ea50c555df836ebe27cccd7d2492b4950",
                "md5": "48da5eb0e552767ba749c5131b38bd8d",
                "sha256": "4b609e585074e5d783812caa2f51958db391c41cebc84eb048d8c370b1cc2fad"
            },
            "downloads": -1,
            "filename": "clients-1.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "48da5eb0e552767ba749c5131b38bd8d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 9739,
            "upload_time": "2025-10-27T23:26:41",
            "upload_time_iso_8601": "2025-10-27T23:26:41.335572Z",
            "url": "https://files.pythonhosted.org/packages/14/04/e155db4558fd8f1fbc6e3baf363ea50c555df836ebe27cccd7d2492b4950/clients-1.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-27 23:26:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "coady",
    "github_project": "clients",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "clients"
}
        
Elapsed time: 3.46935s