Skip to main content

RestyClient is a simple, easy-to-use Python library for interacting with REST APIs using Pydantic's powerful data validation and deserialization tools.

Project description

RestyClient

resty lib logo

GitHub GitHub release (latest by date) PyPI - Downloads Code Style

RestyClient is a simple, easy-to-use Python library for interacting with REST APIs using Pydantic's powerful data validation and deserialization tools. This library provides an intuitive API that makes it easy to make HTTP requests and handle data on the client side.

Features

  • Middleware system, which allows you to implement any pagination, filtering or authentication.

Installation

Using pip:

pip install resty-client

Using Poetry:

poetry add resty-client

Getting-Started

Schema

from pydantic import BaseModel


class Product(BaseModel):
    id: int | None = None
    name: str
    description: str
    code: str

Serializer

from resty.serializers import Serializer


class ProductSerializer(Serializer):
    schema = Product

Manager

from resty.enums import (
    Endpoint,
    Field
)
from resty.managers import Manager


class ProductManager(Manager):
    serializer = ProductSerializer
    endpoints = {
        Endpoint.CREATE: '/products/',
        Endpoint.READ: '/products/',
        Endpoint.READ_ONE: '/products/{pk}/',
        Endpoint.UPDATE: '/products/{pk}/',
        Endpoint.DELETE: '/products/{pk}/',
    }
    fields = {
        Field.PRIMARY: 'id',
    }

CRUD

from httpx import AsyncClient

from resty.clients.httpx import RESTClient


async def main():
    xclient = AsyncClient(base_url='http://localhost:8000/')
    rest_client = RESTClient(xclient=xclient)

    product = Product(
        name='First prod',
        description='My Desc',
        code='123W31Q'
    )

    # Create
    created = await ProductManager.create(rest_client, product)

    # Read
    my_product = await ProductManager.read_one(rest_client, created.id)

    for prod in await ProductManager.read(rest_client):
        print(prod.name)

    # Update
    my_product.description = 'QWERTY'
    await ProductManager.update(rest_client, my_product)

    # Delete
    await ProductManager.delete(rest_client, my_product.id)

Status

0.0.2 - RELEASED

Licence

RestyClient is released under the MIT License. See the bundled LICENSE file for details.

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

resty_client-0.0.2.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.

resty_client-0.0.2-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file resty_client-0.0.2.tar.gz.

File metadata

  • Download URL: resty_client-0.0.2.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.1 Windows/10

File hashes

Hashes for resty_client-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d789bab28f51c19d009115d246ce70e30a7b8c056b71690eb0f6893d3feb527a
MD5 6e867c5f0459e786c93c89fc3cd2585a
BLAKE2b-256 c3f6168e87847fbaa1602a185bc500533bf7a4b0de10d2654e9a3a713e696955

See more details on using hashes here.

File details

Details for the file resty_client-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: resty_client-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.1 Windows/10

File hashes

Hashes for resty_client-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c854e66ee9b9dc8f9e9b088a0d770f50e3dd6a362185024497ea78abff6765cd
MD5 a21752a9fa1fb04c1a3367472e1c153c
BLAKE2b-256 4325954a8669c59b11c823f1749a255efe0803daa91a0e3bcccc709ea10dd1a6

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