Typed python HTTP client wrapper for PRIMP
Project description
CuttlePy
A fully typed Python HTTP client built on top of primp - the fastest Python HTTP client with browser impersonation capabilities.
Acknowledgements
This project is powered by the excellent primp library. CuttlePy provides type hints and a more structured interface while utilizing primp's powerful features under the hood.
Features
- Full type hints support for better IDE integration
- All the power of primp with a typed interface
- Browser impersonation capabilities
- Support for all HTTP methods
- Comprehensive response object with typed properties
Installation
pip install cuttlepy
Usage
Making Requests
from cuttlepy import get, CuttleClient
# Using convenience functions
response = get("https://api.example.com/data")
print(response.json())
# Using the client
client = CuttleClient(
impersonate="chrome_131",
timeout=30
)
response = client.get("https://api.example.com/data")
Response Object
The CuttleResponse object provides typed access to response data:
response = get("https://api.example.com/data")
# Access response properties with proper typing
content: bytes = response.content
status_code: int = response.status_code
headers: Dict[str, str] = response.headers
cookies: CookieJar = response.cookies
text: str = response.text
# Parse JSON with proper typing
data: Any = response.json()
HTTP Methods
All standard HTTP methods are supported with full type hints:
from cuttlepy import CuttleClient
client = CuttleClient()
# GET request
response = client.get(
url="https://api.example.com/data",
params={"key": "value"},
headers={"Authorization": "Bearer token"}
)
# POST request with JSON
response = client.post(
url="https://api.example.com/data",
json={"key": "value"}
)
# POST with form data
response = client.post(
url="https://api.example.com/data",
data={"key": "value"}
)
# POST with files
response = client.post(
url="https://api.example.com/data",
files={"file": open("document.pdf", "rb").read()}
)
Authentication
# Basic auth
client = CuttleClient(auth=("username", "password"))
# Bearer token
client = CuttleClient(auth_bearer="your-token")
Browser Impersonation
client = CuttleClient(impersonate="chrome_131")
📖 API Reference
CuttleClient
class CuttleClient:
def __init__(
self,
*,
auth: Optional[Tuple[str, str]] = None,
auth_bearer: Optional[str] = None,
params: Optional[Dict[str, str]] = None,
headers: Optional[Dict[str, str]] = None,
cookies: Optional[Dict[str, str]] = None,
timeout: float = 30,
cookie_store: bool = True,
referer: bool = True,
proxy: Optional[str] = None,
impersonate: Optional[str] = None,
follow_redirects: bool = True,
max_redirects: int = 20,
verify: bool = True,
ca_cert_file: Optional[str] = None,
http1: Optional[bool] = None,
http2: Optional[bool] = None
): ...
CuttleResponse
class CuttleResponse:
@property
def content(self) -> bytes: ...
@property
def cookies(self) -> CookieJar: ...
@property
def encoding(self) -> Optional[str]: ...
@property
def headers(self) -> Dict[str, str]: ...
@property
def status_code(self) -> int: ...
@property
def text(self) -> str: ...
def json(self) -> Any: ...
@property
def url(self) -> str: ...
def raise_for_status(self) -> None: ...
License
MIT License
Links
- primp Documentation - The underlying HTTP client used by CuttlePy
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 cuttlepy-0.2.2.tar.gz.
File metadata
- Download URL: cuttlepy-0.2.2.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aedeb14fe77e4964117a888a825b564eea497955f2fd315dd1a136e1c8e19b5c
|
|
| MD5 |
658cde49079d376ab5e1075665b4e8d9
|
|
| BLAKE2b-256 |
6028fe61018a69e2f2e1c471732c498bf67cd1a1c1a8b2d99f0e55c50127a0ad
|
File details
Details for the file cuttlepy-0.2.2-py3-none-any.whl.
File metadata
- Download URL: cuttlepy-0.2.2-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e50d9a2533daec738c9d9dd19a2561339e5b8a5b22ee3a89191b8990bceb6ae
|
|
| MD5 |
a6b295becd3fbc5e0e283b5b851b6add
|
|
| BLAKE2b-256 |
47a93d6ae01f861f7166579dd1ef2baea86ec80ba8795564be65069c998c8b60
|