A lightweight asyncio HTTP client
Project description
# bareClient
A simple asyncio http client.
## Description
This package provides the asyncio transport for [h11](https://h11.readthedocs.io/en/latest/index.html).
It makes little attempt to provide any helpful features.
## Installation
This is a Python 3.7 package.
```bash
pip install bareclient
```
## Usage
The basic usage is to create an `HttpClient`.
```python
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.
```python
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.
```python
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))
```
A simple asyncio http client.
## Description
This package provides the asyncio transport for [h11](https://h11.readthedocs.io/en/latest/index.html).
It makes little attempt to provide any helpful features.
## Installation
This is a Python 3.7 package.
```bash
pip install bareclient
```
## Usage
The basic usage is to create an `HttpClient`.
```python
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.
```python
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.
```python
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-0.2.0.tar.gz
(7.6 kB
view hashes)
Built Distribution
bareclient-0.2.0-py3-none-any.whl
(13.7 kB
view hashes)
Close
Hashes for bareclient-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 619a1911a23d2eb2790975b964431be2cfa24444c954697b5c7a7697af1807d6 |
|
MD5 | 9f952493d762b6dc7bc39f7af46b7fa2 |
|
BLAKE2b-256 | 60bc657efa4d1046c7384702937af38c2b2b3a0ad5bea7352f4388505d81e5df |