A client for Swarmauri's crouton.
Project description
Swarmauri's CroutonClient
CroutonClient is a Python library for streamlined REST API interactions, supporting both synchronous and asynchronous operations for CRUD tasks.
Initialization
from crouton_client import CroutonClient
client = CroutonClient(API_ROOT="https://api.example.com", ACCESS_STRING="your-token")
Common Operations
GET
- Synchronous:
response = client.get(resource="items", item_id="123", filters={"status": "active"})
- Asynchronous:
response = await client.aget(resource="items", item_id="123")
POST
- Synchronous:
response = client.post(resource="items", data_obj={"name": "Item", "price": 10.0})
- Asynchronous:
response = await client.apost(resource="items", data_obj={"name": "Item", "price": 10.0})
PUT
- Synchronous:
response = client.put(resource="items", data_obj={"price": 15.0}, item_id="123")
- Asynchronous:
response = await client.aput(resource="items", data_obj={"price": 15.0}, item_id="123")
DELETE
- Synchronous:
response = client.delete(resource="items", item_id="123")
- Asynchronous:
response = await client.adelete(resource="items", item_id="123")
Features
- Synchronous & Asynchronous: Methods available for GET, POST, PUT, DELETE.
- Authentication: Pass
ACCESS_STRINGfor token-based requests. - Auto-Generated IDs:
postandapostauto-generateidfields if not provided. - Logging: Logs all requests and responses for debugging.
Error Handling
Raises ValueError for failed requests:
try:
client.get(resource="invalid")
except ValueError as e:
print(f"Error: {e}")
Summary Table
| Operation | Synchronous | Asynchronous |
|---|---|---|
| GET | get() |
aget() |
| POST | post() |
apost() |
| PUT | put() |
aput() |
| DELETE | delete() |
adelete() |
CroutonClient simplifies REST API interactions, allowing you to focus on application logic instead of repetitive request handling.
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 crouton_client-0.1.6.tar.gz.
File metadata
- Download URL: crouton_client-0.1.6.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f63bf26409c3060da6217b376addcb5d45c6ec8ad09584bdee150ffc7619e102
|
|
| MD5 |
a61dd5eef9f573b2b9b9a6155eda5b70
|
|
| BLAKE2b-256 |
945bb0487ff13dd7bab26d171ab696f86bdc7b886d1ea393b806bcf44bcf61d0
|
File details
Details for the file crouton_client-0.1.6-py3-none-any.whl.
File metadata
- Download URL: crouton_client-0.1.6-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cad32c1f94b73c451ada91289d324592538ee6ac5d26f904265baa584189f12a
|
|
| MD5 |
ae3eb79d032f1865bc27dbe40a8a2230
|
|
| BLAKE2b-256 |
c0a297c2cadc1d0305979ed6d5316b38331f2f21d34f20edef2078c8916c353b
|