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.4.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.4.tar.gz.

File metadata

File hashes

Hashes for gefest_simple_rest_client-1.2025.3.4.tar.gz
Algorithm Hash digest
SHA256 0bdf0a4baa653ab33fbcfefcf0aa033beba306520cfac1bea5b72de9a129be9c
MD5 6e8924b80f6505b997637e90c8875f47
BLAKE2b-256 ff33b3081b50fcb199ac23847cdbe20d88283adfe26dd5ef0f39befbca933303

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gefest_simple_rest_client-1.2025.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0b45143d09c5a2e35b891503a396c3aa84a81cd5cf12d3fb4b30fad492b09779
MD5 09cbca0376f510d763b9ab38b89a000a
BLAKE2b-256 ecc4d79c80d2744087c8100a97f2b18ce61c2e73db6c180965eca0550e47b470

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