A modern Python HTTP client library with built-in authentication and response handling
Project description
make-api-request
A modern Python HTTP client library with built-in authentication and response handling.
Features
- 🚀 Modern async/sync support - Built on httpx with full async/await support
- 🔐 Built-in authentication - Support for API keys, Basic auth, Bearer tokens, and OAuth2
- 📦 Type-safe - Full type hints with Pydantic models
- 🔄 Flexible responses - Handle JSON, binary, and streaming responses
- 🛡️ Error handling - Comprehensive API error handling with detailed context
- ⚡ Performance - Efficient request building and response parsing
Installation
pip install make-api-request
Or with Poetry:
poetry add make-api-request
Quick Start
Basic Usage
import asyncio
from make_api_request import AsyncBaseClient
async def main():
client = AsyncBaseClient("https://api.example.com")
# Simple GET request
response = await client.get("/users")
print(response)
asyncio.run(main())
With Authentication
from make_api_request import AsyncBaseClient, AuthBearer
async def main():
# Bearer token authentication
auth = AuthBearer("your-token-here")
client = AsyncBaseClient(
"https://api.example.com",
auths={"bearer": auth}
)
response = await client.get("/protected-endpoint")
print(response)
asyncio.run(main())
Synchronous Usage
from make_api_request import SyncBaseClient, AuthKey
# API key authentication
auth = AuthKey("x-api-key", "your-api-key")
client = SyncBaseClient(
"https://api.example.com",
auths={"api_key": auth}
)
response = client.get("/users")
print(response)
Authentication Types
API Key Authentication
from make_api_request import AuthKey
# Header-based API key
auth = AuthKey("x-api-key", "your-api-key")
# Query parameter API key
auth = AuthKey("api_key", "your-api-key", location="query")
Bearer Token
from make_api_request import AuthBearer
auth = AuthBearer("your-jwt-token")
Basic Authentication
from make_api_request import AuthBasic
auth = AuthBasic("username", "password")
OAuth2
from make_api_request import OAuth2ClientCredentials
auth = OAuth2ClientCredentials(
token_url="https://auth.example.com/token",
client_id="your-client-id",
client_secret="your-client-secret"
)
Advanced Usage
Custom Request Options
from make_api_request import RequestOptions
options = RequestOptions(
timeout=30.0,
headers={"Custom-Header": "value"},
max_retries=3
)
response = await client.get("/endpoint", options=options)
Binary Responses
# Download a file
binary_response = await client.get("/download/file.pdf")
if isinstance(binary_response, BinaryResponse):
with open("file.pdf", "wb") as f:
f.write(binary_response.content)
Streaming Responses
async with client.stream("GET", "/large-dataset") as response:
async for chunk in response.iter_content():
process_chunk(chunk)
Error Handling
from make_api_request import ApiError
try:
response = await client.get("/might-fail")
except ApiError as e:
print(f"API Error: {e.status_code}")
print(f"Response body: {e.body}")
print(f"Full response: {e.response}")
API Reference
Client Classes
AsyncBaseClient- Asynchronous HTTP clientSyncBaseClient- Synchronous HTTP clientBaseClient- Base class for client implementations
Authentication
AuthKey- API key authentication (header or query parameter)AuthBasic- HTTP Basic authenticationAuthBearer- Bearer token authenticationOAuth2- Base OAuth2 authenticationOAuth2ClientCredentials- OAuth2 client credentials flowOAuth2Password- OAuth2 resource owner password flow
Response Types
BinaryResponse- Binary content responsesStreamResponse- Streaming response handlingAsyncStreamResponse- Async streaming responses
Utilities
RequestOptions- Configure individual requestsQueryParams- Type-safe query parameter handlingApiError- Comprehensive API error information
Development
Setup
git clone <repository-url>
cd make-api-request-py
poetry install
Run Tests
poetry run pytest
Code Quality
# Format code
poetry run black .
# Lint
poetry run ruff check .
# Type checking
poetry run mypy make_api_request/
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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 make_api_request-0.1.3.tar.gz.
File metadata
- Download URL: make_api_request-0.1.3.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68044cd0d16b17db71b69c7ee8cce578752a3d0412f3bc4ab181e1d3abb91d15
|
|
| MD5 |
78cd7aea8bdd40137af0a111f6c7e87e
|
|
| BLAKE2b-256 |
61354c62d90317fb0a5e5ed17a2328530b3bf5f158343270b1723a3b9fa81f19
|
Provenance
The following attestation bundles were made for make_api_request-0.1.3.tar.gz:
Publisher:
release.yml on Sideko-Inc/make-request-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
make_api_request-0.1.3.tar.gz -
Subject digest:
68044cd0d16b17db71b69c7ee8cce578752a3d0412f3bc4ab181e1d3abb91d15 - Sigstore transparency entry: 427712152
- Sigstore integration time:
-
Permalink:
Sideko-Inc/make-request-py@e0307c3c25a957e6e5a319264db88af715cfc15c -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Sideko-Inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e0307c3c25a957e6e5a319264db88af715cfc15c -
Trigger Event:
push
-
Statement type:
File details
Details for the file make_api_request-0.1.3-py3-none-any.whl.
File metadata
- Download URL: make_api_request-0.1.3-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4aaee8e3d68e54656d91d88a29c387c2f15f857244904c4e91640de56e2a67f
|
|
| MD5 |
2987ee432837dfa33dafc9f4c43237b0
|
|
| BLAKE2b-256 |
1e2ccdded7e37734532db1cb2be2788164446a832688dddcaec3d9dfc864e37b
|
Provenance
The following attestation bundles were made for make_api_request-0.1.3-py3-none-any.whl:
Publisher:
release.yml on Sideko-Inc/make-request-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
make_api_request-0.1.3-py3-none-any.whl -
Subject digest:
f4aaee8e3d68e54656d91d88a29c387c2f15f857244904c4e91640de56e2a67f - Sigstore transparency entry: 427712155
- Sigstore integration time:
-
Permalink:
Sideko-Inc/make-request-py@e0307c3c25a957e6e5a319264db88af715cfc15c -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Sideko-Inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e0307c3c25a957e6e5a319264db88af715cfc15c -
Trigger Event:
push
-
Statement type: