A requests-style SDK for APIs
Project description
Integrates - A requests-style SDK for APIs
Integrates is a Python library providing a simple, ergonomic interface for interacting with various API protocols (REST, GraphQL, SOAP) while maintaining the familiar feel of the Python 'requests' library.
Features
- Simple, Pythonic API: Easy to use with sensible defaults, inspired by the popular
requestslibrary - Protocol Adapters: Support for multiple API protocols with a consistent interface
- Authentication: Built-in support for common authentication methods (Basic, Bearer, API Key, OAuth2)
- Middleware: Extensible middleware system for customizing request/response processing
- Sync and Async Support: Use the same API for both synchronous and asynchronous code
- Strong Typing: Full type annotations for better IDE support and static analysis
- Resilient by Default: Strict timeouts, connection verification, and error handling
Installation
pip install integrates
Quick Start
Basic Usage
import integrates as api
# Create a client
client = api.Client()
# Make a GET request
response = client.get("https://api.example.com/users", params={"page": 1})
print(response.json())
# Make a POST request with JSON data
response = client.post(
"https://api.example.com/users",
json={"name": "John Doe", "email": "john@example.com"}
)
print(f"Status: {response.status_code}")
Async Support
import asyncio
import integrates as api
async def main():
async with api.AsyncClient() as client:
response = await client.get("https://api.example.com/users")
print(response.json())
asyncio.run(main())
Authentication
import integrates as api
from integrates.auth import BearerAuth
# Create a client with token authentication
client = api.Client(
base_url="https://api.example.com",
auth=BearerAuth(token="your_access_token")
)
# All requests will include the Authorization header
response = client.get("/users/me")
Middleware
import integrates as api
from integrates.middleware import RetryMiddleware, LoggingMiddleware
# Create a client with middleware
client = api.Client(
middlewares=[
RetryMiddleware(retries=3),
LoggingMiddleware()
]
)
# Requests will automatically retry on failure and be logged
response = client.get("https://api.example.com/data")
Resource Pattern for REST APIs
import integrates as api
# Create a REST client
client = api.RestClient(base_url="https://api.example.com")
# Create a resource
users = client.resource("users")
# Get all users
all_users = users.get()
# Get a specific user
user = users(123).get()
# Create a user
new_user = users.post(json={"name": "Jane Doe"})
# Update a user
updated_user = users(123).put(json={"name": "Jane Smith"})
# Delete a user
users(123).delete()
Documentation
For more detailed documentation, see the examples directory.
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/caiopizzol/integrates.git
cd integrates
# Install development dependencies
pip install -e ".[dev]"
Run Tests
pytest
License
MIT
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
integrates-0.1.1.tar.gz
(13.5 kB
view details)
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 integrates-0.1.1.tar.gz.
File metadata
- Download URL: integrates-0.1.1.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98688fb9b5d4985dd50509a8ea7592882284e346a584ae2f322ffd67eb7e5890
|
|
| MD5 |
0a79dfce373cfc5982b7f5eeb55d0c2f
|
|
| BLAKE2b-256 |
26b0317735fcb129e44ea762997ca12ab56b5399c555fadf3b2a8051b899ebeb
|
File details
Details for the file integrates-0.1.1-py3-none-any.whl.
File metadata
- Download URL: integrates-0.1.1-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcb4fe9f60fed22ab86755a806869569ee9dae3f15618d3fdadba98db83a6273
|
|
| MD5 |
f17dc26a8aa68bbc4ba58945a5e83d1c
|
|
| BLAKE2b-256 |
faf407025576e85075fe709d567bbdea604c1fdcf171a31d7625cd280dcda724
|