A lightweight asyncio HTTP client
Project description
bareClient
A simple asyncio http client supporting HTTP versions 1.0, 1.1 and 2.
The docs are here.
Description
This package provides the asyncio transport for h11, and h2.
It makes little attempt to provide any helpful features which might do unnecessary work.
Installation
This is a Python 3.7 package.
pip install bareclient
Usage
The basic usage is to create an HttpClient
.
import asyncio
from typing import List, Optional
from baretypes import Header
from bareclient import HttpClient
async def main(url: str, headers: Optional[List[Header]]) -> None:
async with HttpClient(url, method='GET', headers=headers) as response:
print(response)
if response['status_code'] == 200 and response['more_body']:
async for part in response['body']:
print(part)
URL = 'https://docs.python.org/3/library/cgi.html'
HEADERS = None
asyncio.run(main(URL, HEADERS))
There is also an HttpSession
for maintaining a session.
import asyncio
import logging
import bareutils.response_code as response_code
from bareclient import HttpSession
logging.basicConfig(level=logging.DEBUG)
async def main() -> None:
session = HttpSession(
'https://shadow.jetblack.net:9009',
capath='/etc/ssl/certs'
)
headers = [
(b'host', b'shadow.jetblack.net'),
(b'connection', b'close')
]
for path in ['/example1', '/example2', '/empty']:
async with session.request(path, method='GET', headers=headers) as response:
print(response)
if not response_code.is_successful(response['status_code']):
print("failed")
else:
if response['status_code'] == response_code.OK and response['more_body']:
async for part in response['body']:
print(part)
asyncio.run(main())
Finally there is a single helper function to get json.
import asyncio
from bareclient import get_json
async def main(url: str) -> None:
"""Get some JSON"""
obj = await get_json(url, headers=[(b'accept-encoding', b'gzip')])
print(obj)
URL = 'https://jsonplaceholder.typicode.com/todos/1'
asyncio.run(main(URL))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bareclient-4.0.0rc1.tar.gz
(19.0 kB
view hashes)
Built Distribution
Close
Hashes for bareclient-4.0.0rc1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d084ca12711ef25a3f6d087deb6d6eb854a8a0de50b3af4599ab18b9f02da713 |
|
MD5 | 7bbf1d63b3d36cfa107625095aa6396f |
|
BLAKE2b-256 | 1797834e889aafca78def09a1ff6f0a6fc7db864def3717d14b5e3a3fddfea38 |