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

File metadata

File hashes

Hashes for gefest_simple_rest_client-1.2025.3.16.tar.gz
Algorithm Hash digest
SHA256 40df3d83c623330778e73f25b8febf3b76ae2b2ea2a3eb9bb98a7f8c8f2491c6
MD5 970da31c4a1495de7ea6546ec554d8b3
BLAKE2b-256 5dd3c478c8a958dfc91f042bf592883c102bc31d637be6e15ab49ce40180ec30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gefest_simple_rest_client-1.2025.3.16-py3-none-any.whl
Algorithm Hash digest
SHA256 af82a5fa266eeb096f5e80b8b61c20792aff113a6881670f5292277a58707b90
MD5 eef50c60775757e53d60a573b9a767c3
BLAKE2b-256 1925f6e564fc21f8f32046f15e837ca4af68ae6eb59de9360abe5c1742a7e06b

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