High-performance HTTP client library powered by Go FastHTTP
Project description
GoRequests - High-Performance HTTP Client
GoRequests is a high-performance HTTP client library for Python, powered by Go's FastHTTP backend. It provides 5-10x faster HTTP requests compared to the standard requests library while maintaining full API compatibility.
🚀 Key Features
- 🔥 Blazing Fast: 5-10x performance improvement over standard requests
- 🔄 Drop-in Replacement: 100% compatible with
requestslibrary API - ⚡ Go/FastHTTP Backend: Leverages Go's high-performance HTTP implementation
- 🛠️ Zero Configuration: Auto-setup, no manual configuration required
- 📦 Easy Integration: Simple import and use, no helper functions needed
- 🎯 Production Ready: Battle-tested with comprehensive error handling
- 💾 Memory Efficient: Optimized memory management with Go garbage collector
- 🌐 Full HTTP Support: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
📊 Performance Comparison
| Library | Requests/sec | Memory Usage | Setup Complexity |
|---|---|---|---|
| GoRequests | ~2,500/sec | Low | Zero config |
| Standard Requests | ~250/sec | Medium | Simple |
| aiohttp | ~1,800/sec | Medium | Complex |
| httpx | ~1,200/sec | Medium | Medium |
Benchmark Results
GoRequests vs Standard Requests Performance Test:
├── Single Request: 60% faster (0.48s vs 1.2s)
├── 100 Concurrent: 800% faster (2.1s vs 16.8s)
├── 1000 Sequential: 650% faster (45s vs 295s)
└── Memory Usage: 40% less memory consumption
� Performance Comparison
GoRequests delivers 5-10x performance improvements over the standard Python requests library:
| Metric | GoRequests | Standard Requests | Improvement |
|---|---|---|---|
| Single Request | 0.48s | 1.2s | 60% faster |
| 100 Concurrent | 2.1s | 16.8s | 800% faster |
| 1000 Sequential | 45s | 295s | 650% faster |
| Memory Usage | Low | Medium | 40% less |
| Requests/second | ~2,500 | ~250 | 10x throughput |
Why GoRequests is Faster
- Go Backend: Powered by Go's high-performance FastHTTP library
- Native Compilation: Pre-compiled Go library eliminates Python overhead
- Efficient Memory Management: Go's garbage collector optimizes memory usage
- Connection Pooling: Advanced connection reuse and management
- Zero Python Overhead: Direct C bindings bypass Python HTTP stack
�🛠️ Installation
Install from PyPI (Recommended)
pip install gorequests
Install from Source
git clone https://github.com/coffeecms/gorequests.git
cd gorequests
pip install -e .
Requirements
- Python 3.7+
- Windows, macOS, or Linux
- Pre-compiled Go library (included in package)
💡 Usage Examples
1. Basic HTTP Requests (Drop-in Replacement)
import gorequests as requests
# GET request
response = requests.get('https://api.github.com/users/octocat')
print(f"Status: {response.status_code}")
print(f"JSON: {response.json()}")
# POST with JSON
response = requests.post('https://httpbin.org/post',
json={'key': 'value', 'number': 42})
print(f"Response: {response.text}")
# Custom headers and parameters
response = requests.get('https://api.github.com/search/repositories',
params={'q': 'python', 'sort': 'stars'},
headers={'User-Agent': 'MyApp/1.0'})
2. Advanced Usage with Sessions
import gorequests
# Create a session for connection reuse
session = gorequests.Session()
# Login example
login_data = {'username': 'user', 'password': 'pass'}
session.post('https://example.com/login', json=login_data)
# Subsequent requests use the same session
profile = session.get('https://example.com/profile')
settings = session.get('https://example.com/settings')
# Session automatically handles cookies and authentication
3. Error Handling and Timeouts
import gorequests
from gorequests.exceptions import GoRequestsError, TimeoutError
try:
response = gorequests.get('https://api.example.com/data',
timeout=5, # 5 second timeout
headers={'Accept': 'application/json'})
if response.ok:
data = response.json()
print(f"Success: {data}")
else:
print(f"HTTP Error: {response.status_code}")
except TimeoutError:
print("Request timed out")
except GoRequestsError as e:
print(f"GoRequests error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
4. File Upload and Download
import gorequests
# File upload
with open('document.pdf', 'rb') as f:
files = {'file': ('document.pdf', f, 'application/pdf')}
response = gorequests.post('https://api.example.com/upload', files=files)
# Large file download with streaming
response = gorequests.get('https://example.com/largefile.zip', stream=True)
with open('downloaded_file.zip', 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
# Multiple file upload
files = {
'file1': open('file1.txt', 'rb'),
'file2': open('file2.txt', 'rb')
}
response = gorequests.post('https://api.example.com/multi-upload', files=files)
5. Performance Monitoring and Statistics
import gorequests
import time
# Performance monitoring
start_time = time.time()
# Make multiple requests
responses = []
urls = ['https://httpbin.org/get'] * 10
for url in urls:
response = gorequests.get(url, params={'index': len(responses)})
responses.append(response.status_code)
elapsed = time.time() - start_time
print(f"10 requests completed in {elapsed:.2f}s")
print(f"Average: {elapsed/10:.3f}s per request")
# Memory statistics
stats = gorequests.get_memory_stats()
print(f"Memory usage: {stats['alloc']:,} bytes")
print(f"Active sessions: {stats['sessions']}")
print(f"Goroutines: {stats['goroutines']}")
# Performance comparison helper
def benchmark_comparison():
import requests as std_requests
# Standard requests timing
start = time.time()
std_requests.get('https://httpbin.org/get')
std_time = time.time() - start
# GoRequests timing
start = time.time()
gorequests.get('https://httpbin.org/get')
go_time = time.time() - start
improvement = (std_time / go_time) * 100
print(f"GoRequests is {improvement:.1f}% faster!")
🔧 Advanced Configuration
Custom Client Configuration
import gorequests
# Create client with custom settings
client = gorequests.GoRequestsClient(
dll_path="/custom/path/libgorequests.dll", # Custom library path
auto_setup=True # Auto-configure (default: True)
)
# Use custom client
response = client.get('https://api.example.com')
Environment Variables
# Optional: Custom library path
export GOREQUESTS_DLL_PATH="/path/to/libgorequests.dll"
# Optional: Enable debug mode
export GOREQUESTS_DEBUG=1
📈 Performance Optimization Tips
1. Use Sessions for Multiple Requests
# ❌ Slow: Creates new connection each time
for i in range(100):
gorequests.get(f'https://api.example.com/item/{i}')
# ✅ Fast: Reuses connections
session = gorequests.Session()
for i in range(100):
session.get(f'https://api.example.com/item/{i}')
2. Optimize Timeouts
# ✅ Set appropriate timeouts
response = gorequests.get('https://api.example.com',
timeout=5, # 5 second timeout
connect_timeout=2) # 2 second connect timeout
3. Use Streaming for Large Files
# ✅ Memory efficient for large downloads
response = gorequests.get('https://example.com/large-file.zip', stream=True)
🔍 Migration from Requests
GoRequests is designed as a drop-in replacement. Simply change your import:
# Before
import requests
response = requests.get('https://api.example.com')
# After - 5-10x faster!
import gorequests as requests
response = requests.get('https://api.example.com')
API Compatibility
- ✅
requests.get(),requests.post(), etc. - ✅
Session()class - ✅ Response objects (
response.json(),response.text, etc.) - ✅ Exception handling
- ✅ Timeouts and headers
- ✅ File uploads/downloads
- ✅ Authentication methods
🧪 Testing
# Run tests
python -m pytest tests/
# Run performance benchmarks
python examples/benchmark.py
# Run compatibility tests
python tests/test_compatibility.py
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
git clone https://github.com/coffeecms/gorequests.git
cd gorequests
pip install -e ".[dev]"
python -m pytest
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built with Go and FastHTTP
- Inspired by Python's requests library
- Thanks to the Go and Python communities
📞 Support
- GitHub Issues: https://github.com/coffeecms/gorequests/issues
- Documentation: https://gorequests.readthedocs.io
- PyPI: https://pypi.org/project/gorequests/
🔗 Links
- GitHub Repository: https://github.com/coffeecms/gorequests
- PyPI Package: https://pypi.org/project/gorequests/
- Documentation: https://gorequests.readthedocs.io
Made with ❤️ by the GoRequests Team
Transform your HTTP requests with the power of Go!
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gorequests-2.0.0.tar.gz.
File metadata
- Download URL: gorequests-2.0.0.tar.gz
- Upload date:
- Size: 4.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe5daa824157d9757649c1043fb2f5b0b142e4c79f2553467c99104d66a8e9bc
|
|
| MD5 |
6a811c4bcf126c6831fba4bbcd946340
|
|
| BLAKE2b-256 |
fb6cd0b578a0a669086dd80cc0e49693f2e7d8ad5a58a0099a5d0999f73be1c6
|
File details
Details for the file gorequests-2.0.0-py3-none-any.whl.
File metadata
- Download URL: gorequests-2.0.0-py3-none-any.whl
- Upload date:
- Size: 4.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6269ffa253bb197c2439dea132431bbe2b3d9fd0830ab4444506834d45a3430c
|
|
| MD5 |
b0acbd26c71d0822adbc01f54e3e8101
|
|
| BLAKE2b-256 |
ce38bb0c1b9a49714328d2328445ee0aef47004264d0825a2787056b7c511ff6
|