API Reference
Client
class Client(api_key=None, timeout=30, retry=True)
The main client class for interacting with the API.
Parameters:
api_key(str): Your API key for authenticationtimeout(int): Request timeout in secondsretry(bool): Enable automatic retries on failure
Methods
get(endpoint, params=None)
Perform a GET request.
Parameters:
endpoint(str): API endpoint pathparams(dict): Query parameters
Returns: Response object
Raises: APIError if the API returns an error
response = client.get('/users/123')
post(endpoint, data=None)
Perform a POST request.
Parameters:
endpoint(str): API endpoint pathdata(dict): Request body data
Returns: Response object
data = {'name': 'John', 'email': 'john@example.com'}
response = client.post('/users', data=data)
put(endpoint, data=None)
Perform a PUT request.
Parameters:
endpoint(str): API endpoint pathdata(dict): Request body data
Returns: Response object
updates = {'name': 'Jane'}
response = client.put('/users/123', data=updates)
delete(endpoint)
Perform a DELETE request.
Parameters:
endpoint(str): API endpoint path
Returns: Response object
response = client.delete('/users/123')
Response
Represents an API response.
Attributes:
status_code(int): HTTP status codedata(dict): Response body dataheaders(dict): Response headers
Methods
json()
Parse response as JSON.
Returns: Parsed JSON data
Exceptions
APIError
Raised when the API returns an error.
NetworkError
Raised when a network error occurs.
AuthenticationError
Raised when authentication fails.
RateLimitError
Raised when rate limit is exceeded.
Constants
API_BASE_URL
The base URL for API requests.
API_BASE_URL = 'https://api.example.com'
API_VERSION
The current API version.
API_VERSION = 'v1'
Examples
Initialization
from your_package import Client
client = Client(api_key='your-key')
Get a resource
response = client.get('/users/123')
if response.status_code == 200:
print(response.data)
Create a resource
data = {'name': 'John', 'email': 'john@example.com'}
response = client.post('/users', data=data)
Error handling
try:
response = client.get('/users/123')
except APIError as e:
print(f"Error: {e}")