A fast and flexible HTTP client for Python with sync and async support.
Project description
HyperIO
HyperIO is a fast and flexible HTTP client for Python, supporting both synchronous and asynchronous requests. It includes built-in methods for handling login, registration, file downloads, and HTML rendering. Perfect for making fast and clean HTTP requests in any Python project.
Features
- Synchronous and Asynchronous HTTP Requests (GET, POST, PUT, DELETE)
- Login and Register Functions
- HTML Rendering with BeautifulSoup
- File Downloads (Sync and Async)
- Customizable Headers and Sessions
Installation
To install HyperIO, you can use pip:
pip install hyperio
Usage
# Importing the required classes from the hyperio package
import hyperio
from hyperio import HyperIO, AsyncHyperIO
# Synchronous Example - Using HyperIO
def sync_usage():
print("Synchronous HTTP Request Example:")
# Create a synchronous client
client = HyperIO()
# Making a GET request
response = client.get("https://jsonplaceholder.typicode.com/posts/1")
if response.ok:
print("GET Response:", response.json())
else:
print("Failed to retrieve data")
# Making a POST request
data = {"title": "foo", "body": "bar", "userId": 1}
post_response = client.post("https://jsonplaceholder.typicode.com/posts", json=data)
if post_response.ok:
print("POST Response:", post_response.json())
else:
print("Failed to post data")
# HTML rendering using the view_html function
html_content = client.view_html("https://example.com")
print("HTML Content (first 200 chars):", html_content[:200])
# File download example (sync)
client.download_file("https://www.example.com/somefile.txt", "somefile.txt")
print("File downloaded successfully.")
# Asynchronous Example - Using AsyncHyperIO
import asyncio
async def async_usage():
print("\nAsynchronous HTTP Request Example:")
# Create an asynchronous client
client = AsyncHyperIO()
# Making a GET request asynchronously
response = await client.get("https://jsonplaceholder.typicode.com/posts/1")
if response['ok']:
print("GET Response:", response['json'])
else:
print("Failed to retrieve data")
# Making a POST request asynchronously
data = {"title": "foo", "body": "bar", "userId": 1}
post_response = await client.post("https://jsonplaceholder.typicode.com/posts", json=data)
if post_response['ok']:
print("POST Response:", post_response['json'])
else:
print("Failed to post data")
# HTML rendering asynchronously using the view_html function
html_content = await client.view_html("https://example.com")
print("HTML Content (first 200 chars):", html_content[:200])
# File download example (async)
await client.download_file("https://www.example.com/somefile.txt", "somefile_async.txt")
print("File downloaded successfully.")
# Closing the client session
await client.close()
# Running the examples
if __name__ == "__main__":
sync_usage() # Run the synchronous example
asyncio.run(async_usage()) # Run the asynchronous example
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
hyper_io3-0.1.0.tar.gz
(4.7 kB
view details)
File details
Details for the file hyper_io3-0.1.0.tar.gz.
File metadata
- Download URL: hyper_io3-0.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5005e6915967f4181b302ba8e79ba47ad9233d0bbf210ee310e4f1288ae89543
|
|
| MD5 |
266b6308be840f99aa880c7c97d5bc87
|
|
| BLAKE2b-256 |
a495a7af48946a7c075c92044e753305f55ecfc13da93cb5252c6ee8ce1ebd4b
|