A lightweight asyncio HTTP client
Project description
bareClient
A simple asyncio http client.
Description
This package provides the asyncio transport for h11.
It makes little attempt to provide any helpful features.
Installation
This is a Python 3.7 package.
pip install bareclient
Usage
The basic usage is to create an HttpClient
.
import asyncio
from bareclient import HttpClient
import ssl
async def main(url, headers, ssl):
async with HttpClient(url, method='GET', headers=headers, ssl=ssl) as (response, body):
print(response)
if response.status_code == 200:
async for part in body():
print(part)
url = 'https://docs.python.org/3/library/cgi.html'
headers = [(b'host', b'docs.python.org'), (b'connection', b'close')]
ssl_context = ssl.SSLContext()
loop = asyncio.get_event_loop()
loop.run_until_complete(main(url, headers, ssl_context))
There is also an HttpSession
for keep-alive connections.
import asyncio
from bareclient import HttpSession
import ssl
async def main(url, headers, paths, ssl):
async with HttpSession(url, ssl=ssl) as requester:
for path in paths:
response, body = await requester.request(path, method='GET', headers=headers)
print(response)
if response.status_code == 200:
async for part in body():
print(part)
url = 'https://docs.python.org'
headers = [(b'host', b'docs.python.org'), (b'connection', b'keep-alive')]
paths = ['/3/library/cgi.html', '/3/library/urllib.parse.html']
ssl_context = ssl.SSLContext()
loop = asyncio.get_event_loop()
loop.run_until_complete(main(url, headers, paths, ssl_context))
Finally there is a single helper function to get json.
import asyncio
import ssl
from bareclient import get_json
async def main(url, ssl):
obj = await get_json(url, ssl=ssl)
print(obj)
url = 'https://jsonplaceholder.typicode.com/todos/1'
ssl_context = ssl.SSLContext()
loop = asyncio.get_event_loop()
loop.run_until_complete(main(url, ssl_context))
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-3.0.0.tar.gz
(6.7 kB
view hashes)
Built Distribution
bareclient-3.0.0-py3-none-any.whl
(12.5 kB
view hashes)
Close
Hashes for bareclient-3.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a09c9a9a52ebd67d5f7f8c291296210bb1d1ea27f8e2dc8294fc819a7e246f74 |
|
MD5 | 4aa080acac9cc5d40246c82d5ec78e1d |
|
BLAKE2b-256 | b04e7600ff1764390b662ea699e25860ba115dd373d397b91a12daa1dba18651 |