Registry / http-networking / simple-rest-client

simple-rest-client

JSON →
library1.2.1pypypi✓ verified 80d ago

Simple REST client for Python 3.8+ that aims to make interacting with REST APIs straightforward. It provides a clean API for defining resources and actions, handles HTTP requests, and parses responses. Currently at version 1.2.1, it follows a stable release cadence with updates addressing bug fixes and minor improvements, focusing on simplicity and ease of use.

pip install simple-rest-client
INSTALL
IMPORT
SIG · SIMPLE-REST-CLIENT
S
simple-rest-client
http-networkingpythonv1.2.1
Install
3.1s avg
Import
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 23.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.1s · import 0.000s · 24MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SimpleRestClient
import simple_rest_client
from simple_rest_client import SimpleRestClient

This quickstart demonstrates how to initialize `SimpleRestClient`, define a `Resource` class, and perform common REST operations like `list`, `get`, and `create` against a public API. It includes an example of handling authentication headers and emphasizes best practices like enabling SSL verification.

import os from simple_rest_client.client import SimpleRestClient from simple_rest_client.resource import Resource # Define a resource for users. Basic CRUD actions (list, get, create, update, delete) are # automatically available if not overridden or custom actions defined. class UserResource(Resource): pass # Initialize the client for a public API (e.g., JSONPlaceholder). # In a production environment, ensure ssl_verify is True and handle authentication. client = SimpleRestClient( api_root_url="https://jsonplaceholder.typicode.com/", ssl_verify=True, # Always prefer True in production. Set to False only for testing untrusted SSL. headers={ "Authorization": f"Bearer {os.environ.get('API_KEY', '')}" } # Example for authentication token ) # Add the user resource to the client, making it accessible via client.users client.add_resource(resource_name="users", resource_class=UserResource) try: # Example 1: Get all users print("\nFetching all users...") all_users = client.users.list() print(f"First user: {all_users[0]['name']}") # Example 2: Get a single user by ID print("\nFetching user with ID 1...") user_1 = client.users.get(1) print(f"User 1 name: {user_1['name']}, email: {user_1['email']}") # Example 3: Create a new user (NOTE: JSONPlaceholder is a fake API; this won't persist) print("\nCreating a new user (API will return 201, but not persist on JSONPlaceholder)...") new_user_data = { "name": "Jane Doe", "username": "janedoe", "email": "jane.doe@example.com", "address": {"street": "123 Main St"} } created_user = client.users.create(new_user_data) print(f"Created user ID: {created_user.get('id', 'N/A')}, Name: {created_user['name']}") except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
breakingPrior to version 1.0.0, the primary method for defining API interactions was `client.get_action()`. Version 1.0.0 introduced `client.add_resource()` and the `Resource` class, which are now the recommended and more powerful approach for CRUD operations and custom endpoints.
fix
Migrate existing `get_action` usages to define `Resource` classes with custom actions or use default CRUD methods via `add_resource`. This provides a more structured and extensible way to interact with your API.
affects: <1.0.0
gotchaThe `ssl_verify=False` parameter, often seen in examples or used during development, disables SSL certificate verification. Using this in a production environment makes connections vulnerable to man-in-the-middle attacks.
fix
Always ensure `ssl_verify=True` (the default) in production environments. If connecting to internal APIs with self-signed certificates, configure your system to trust the CA certificate or pass the certificate path to `ssl_verify`.
affects: All
gotchaBy default, `simple-rest-client` raises exceptions (e.g., `simple_rest_client.exceptions.ClientError`, `BadRequestError`, `UnauthorizedError`) for non-2xx HTTP responses. Users unfamiliar with this might not implement proper error handling, leading to unhandled exceptions.
fix
Wrap API calls in `try...except simple_rest_client.exceptions.ClientError as e:` blocks (or more specific HTTP exception types) to gracefully handle API errors. Inspect `e.status_code` and `e.message` for details.
affects: All
Upgrade
Version history
1.2.1latest on PyPI · released Oct 3, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
12
OpenAI (training)
2
Amazon
1
Resources
simple-rest-client — pip install simple-rest-client · libregistry