Skip to main content

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


Download files

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

Source Distribution

gefest_simple_rest_client-1.2025.3.5.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file gefest_simple_rest_client-1.2025.3.5.tar.gz.

File metadata

File hashes

Hashes for gefest_simple_rest_client-1.2025.3.5.tar.gz
Algorithm Hash digest
SHA256 8a3212fe06b6dbb2ff568ce736b9113e7b4ffe0aa9f5ed742cf85d78e8d0fcf2
MD5 81f7b1dd8a251187b97a315a64fd1ebe
BLAKE2b-256 55ad43258e50c5dd8c7a3d63f3e32fc9518d3f50908cd3dbc5e144fc3d74efe7

See more details on using hashes here.

File details

Details for the file gefest_simple_rest_client-1.2025.3.5-py3-none-any.whl.

File metadata

File hashes

Hashes for gefest_simple_rest_client-1.2025.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 33cdbd749c39fd5985ffdc2bace3f076265ceddc404e20ff8fcf2934b603f269
MD5 b7a0c4620653831ff17ae3038aa5070f
BLAKE2b-256 73b54cc2d96adcd32e60b34b2cdeb37fdf1f183b1bb0ced8693af7ee765048d8

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