Skip to main content

H2Client

This library is intended to provide improved control when writing an http/2 client without adding a significant amount of boilerplate. In particular this allows for easy connection management, since when an http/2 connection is opened and closed will have a very significant impact on performance, and respects Cache-Control headers (request and response) using diskcached, since respecting these headers is often an insane performance improvement as it will prevent a large number of requests from requiring any network calls at all.

This does not support ETag style validation as it doesn't tend to result in any significant improvements on REST api's where even the largest responses are measured in kilobytes since ETags do not prevent network calls.

Getting Started

python -m venv venv
. venv/bin/activate  # for windows, "venv/Scripts/activate.bat"
python -m pip install --upgrade pip
pip install h2client
"""Make some requests using the postman-echo service run by
https://www.postman.com/. h2client is not in any way affiliated with or
endorsed by Postman.
"""
import asyncio
from h2client.session import Session
import json


USER_AGENT = 'H2ClientExamples/1 by /u/Tjstretchalot (+https://github.com/tjstretchalot/h2client)'


async def main():
    client = Session(
        'postman-echo.com',
        default_headers={
            'user-agent': USER_AGENT,
            'accept': 'application/json'
        }
    )

    async with client.conn() as conn:
        responses = await asyncio.gather(
            conn.get('/get', params={'foo1': 'bar1'}),
            conn.post('/post', json={'payload': 'asdf'}),
            conn.delete('/delete', data=b'look some data!', headers={
                'content-type': 'text/plain'
            })
        )

    for response in responses:
        print(f'{response.method} {response.path} - {response.status_code} {response.status_text}')
        print('Request Headers:')
        for key, val in response.request_headers.items():
            print(f'  {key}: {val}')

        print('Headers:')
        for key, val in response.headers.items():
            print(f'  {key}: {val}')

        print()
        print('Body (interpreted):')
        print(json.dumps(response.json(), indent=2, sort_keys=True))


if __name__ == '__main__':
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop.run_until_complete(main())

    # Wait for the `ensure_future`s to finish cleanly
    pending = asyncio.all_tasks(loop)
    while pending:
        loop.run_until_complete(asyncio.wait(pending, return_when=asyncio.ALL_COMPLETED))
        pending = asyncio.all_tasks(loop)

Metadata

Release files for h2client 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for h2client 0.2.3
File Size Uploaded
h2client-0.2.3.tar.gz 18.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for h2client 0.2.3
File Interpreter ABI Platform
h2client-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 40.1 kB

Release files / h2client-0.2.3.tar.gz

Download URL h2client-0.2.3.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
17f6e29a274db8d9b4d05806daf5093d7ff987c58ee768caa6b52c488a3271db
BLAKE2b-256 checksum
How to use checksums
198598a53d44a0be5fde70ab34dc8592b889ecef61df13b7d67a31479461650a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.5

Release files / h2client-0.2.3-py3-none-any.whl

Download URL h2client-0.2.3-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ec31f5055e622ff1e86d44d0fb0817cfe3677566d03570b2b115ad6847f2e96
BLAKE2b-256 checksum
How to use checksums
514001a31567dd92b00195b762d01ab61a453287db928573f58ac2eb388996fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.5

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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