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.
- π₯ Blazing Fast: 5-10x performance improvement over standard requests
- π Drop-in Replacement: 100% compatible with
requests
library 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
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 |
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
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 |
- 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
pip install gorequests
git clone https://github.com/coffeecms/gorequests.git
cd gorequests
pip install -e .
- Python 3.7+
- Windows, macOS, or Linux
- Pre-compiled Go library (included in package)
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'})
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
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}")
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)
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!")
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')
# Optional: Custom library path
export GOREQUESTS_DLL_PATH="/path/to/libgorequests.dll"
# Optional: Enable debug mode
export GOREQUESTS_DEBUG=1
# β 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}')
# β
Set appropriate timeouts
response = gorequests.get('https://api.example.com',
timeout=5, # 5 second timeout
connect_timeout=2) # 2 second connect timeout
# β
Memory efficient for large downloads
response = gorequests.get('https://example.com/large-file.zip', stream=True)
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')
- β
requests.get()
,requests.post()
, etc. - β
Session()
class - β
Response objects (
response.json()
,response.text
, etc.) - β Exception handling
- β Timeouts and headers
- β File uploads/downloads
- β Authentication methods
# Run tests
python -m pytest tests/
# Run performance benchmarks
python examples/benchmark.py
# Run compatibility tests
python tests/test_compatibility.py
We welcome contributions! Please see our Contributing Guide for details.
git clone https://github.com/coffeecms/gorequests.git
cd gorequests
pip install -e ".[dev]"
python -m pytest
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Go and FastHTTP
- Inspired by Python's requests library
- Thanks to the Go and Python communities
- GitHub Issues: https://github.com/coffeecms/gorequests/issues
- Documentation: https://gorequests.readthedocs.io
- PyPI: https://pypi.org/project/gorequests/
- 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!