Abstractions for create REST API client
Project description
Gefest Simple REST Client
Description
Gefest Simple REST Client is a library designed to simplify the creation of REST API clients in Python. Built on httpx, it provides both synchronous and asynchronous API interaction.
Features
- 🛠️ Abstraction of clients and endpoints
- ⚙️ Support for both synchronous (
httpx.Client) and asynchronous (httpx.AsyncClient) request models - ✅ Dynamic access to endpoints
- ✨ URL templates for handling path parameters
Installation
pip install gefest_simple_rest_client
Usage Example
from gefest_simple_rest_client.client import BaseClient
from gefest_simple_rest_client.endpoint import BaseEndpoint, PathTemplate
class MyEndpoint(BaseEndpoint):
name = "example"
path_template = PathTemplate("/example/{id:int}")
class MyClient(BaseClient):
base_url = "https://api.example.com"
headers = {"Authorization": "Bearer YOUR_TOKEN"}
endpoints = [MyEndpoint]
client = MyClient()
Synchronous Usage
response = client.example.get(path_params={"id": 123})
print(response.json())
Asynchronous Usage
import asyncio
async def fetch():
async with MyClient() as client:
response = await client.example.get_async(path_params={"id": 123})
print(response.json())
asyncio.run(fetch())
Errors when Passing Invalid Path Parameters
If incorrect parameters are provided, exceptions are raised:
try:
response = client.example.get(path_params={"id": "invalid_string"})
except Exception as e:
print(f"Error: {e}")
Example error:
PathParamsValidationError: Parameter 'id' must be of type int
Feedback
If you have any questions or suggestions, feel free to reach out via GitHub Issues.
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 gefest_simple_rest_client-1.2025.3.5.tar.gz.
File metadata
- Download URL: gefest_simple_rest_client-1.2025.3.5.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a3212fe06b6dbb2ff568ce736b9113e7b4ffe0aa9f5ed742cf85d78e8d0fcf2
|
|
| MD5 |
81f7b1dd8a251187b97a315a64fd1ebe
|
|
| BLAKE2b-256 |
55ad43258e50c5dd8c7a3d63f3e32fc9518d3f50908cd3dbc5e144fc3d74efe7
|
File details
Details for the file gefest_simple_rest_client-1.2025.3.5-py3-none-any.whl.
File metadata
- Download URL: gefest_simple_rest_client-1.2025.3.5-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33cdbd749c39fd5985ffdc2bace3f076265ceddc404e20ff8fcf2934b603f269
|
|
| MD5 |
b7a0c4620653831ff17ae3038aa5070f
|
|
| BLAKE2b-256 |
73b54cc2d96adcd32e60b34b2cdeb37fdf1f183b1bb0ced8693af7ee765048d8
|