apiclient is a simple, lightweight Python framework for building API clients for REST-like services, leveraging `urllib3` for HTTP requests. It provides decorators for defining API endpoints and handles the boilerplate of request building and response processing. The current version is 1.0.4, with recent minor updates indicating active maintenance.
pip install apiclientVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to define a simple GitHub API client using `APIClient` and the `endpoint` decorator. It fetches public repositories for a given user, explicitly handles the response object for status checking and JSON parsing, and includes basic error handling for network and HTTP errors.
After calling an `endpoint` method, always follow up with `response.raise_for_status()` to check for errors and `response.json()` (or `response.text`, `response.content`) to access the response body.
Extend the `APIClient` or specific endpoint methods with custom logic to handle retries, rate limits, or other advanced scenarios using `urllib3` directly or other helper libraries.
Keep `urllib3` updated to a version compatible with `apiclient` (and address any `urllib3` specific warnings). Monitor `urllib3` release notes for changes relevant to HTTP client behavior.
Verify network connection, check `base_url` for typos, ensure the target API server is online and accessible. Consider adding retry logic to your client.
Ensure your authentication headers are correctly set (e.g., `Authorization` header), verify the API key/token is valid, and double-check the `endpoint` path and method (e.g., `get` vs. `post`). Remember to call `response.raise_for_status()` to explicitly raise these HTTP errors.