Skip to main content

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

  1. Synchronous & Asynchronous: Methods available for GET, POST, PUT, DELETE.
  2. Authentication: Pass ACCESS_STRING for token-based requests.
  3. Auto-Generated IDs: post and apost auto-generate id fields if not provided.
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crouton_client-0.1.6.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crouton_client-0.1.6-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

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

Hashes for crouton_client-0.1.6.tar.gz
Algorithm Hash digest
SHA256 f63bf26409c3060da6217b376addcb5d45c6ec8ad09584bdee150ffc7619e102
MD5 a61dd5eef9f573b2b9b9a6155eda5b70
BLAKE2b-256 945bb0487ff13dd7bab26d171ab696f86bdc7b886d1ea393b806bcf44bcf61d0

See more details on using hashes here.

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

Hashes for crouton_client-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 cad32c1f94b73c451ada91289d324592538ee6ac5d26f904265baa584189f12a
MD5 ae3eb79d032f1865bc27dbe40a8a2230
BLAKE2b-256 c0a297c2cadc1d0305979ed6d5316b38331f2f21d34f20edef2078c8916c353b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page