Socket
Socket
Sign inDemoInstall

resty-client

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resty-client

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


Maintainers
1

Resty-Client

resty lib logo

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

Resty-Client 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.
  • Powerful data validation & deserialization using Pydantic
  • Easy-to-Use

Installation

Using pip:

pip install resty-client

Using Poetry:

poetry add resty-client

Getting-Started

See examples for more.

Schemas

from resty.types import Schema


class UserCreateSchema(Schema):
    username: str
    email: str
    password: str
    age: int


class UserReadSchema(Schema):
    id: int
    username: str
    email: str
    age: int


class UserUpdateSchema(Schema):
    username: str = None
    email: str = None

Manager

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


class UserManager(Manager):
    endpoints = {
        Endpoint.CREATE: "users/",
        Endpoint.READ: "users/",
        Endpoint.READ_ONE: "users/{pk}",
        Endpoint.UPDATE: "users/{pk}",
        Endpoint.DELETE: "users/{pk}",
    }
    fields = {
        Field.PRIMARY: "id",
    }

CRUD

import asyncio

import httpx

from resty.clients.httpx import RESTClient


async def main():
    client = RESTClient(httpx.AsyncClient(base_url="https://localhost:8000"))

    manager = UserManager(client=client)

    response = await manager.create(
        obj=UserCreateSchema(
            username="admin",
            email="admin@admin.com",
            password="admin",
            age=19,
        ),
        response_type=UserReadSchema,
    )
    print(response)  # id=1 username='admin' email='admin@admin.com' age=19

    response = await manager.read(
        response_type=UserReadSchema,
    )

    for obj in response:
        print(obj)  # id=1 username='admin' email='admin@admin.com' age=19

    response = await manager.read_one(
        obj_or_pk=1,
        response_type=UserReadSchema,
    )

    print(response)  # id=1 username='admin' email='admin@admin.com' age=19

    response = await manager.update(
        obj=UserUpdateSchema(
            id=1,
            username="admin123",
        ),
        response_type=UserReadSchema,
    )

    print(response)  # id=1 username='admin123' email='admin@admin.com' age=19

    await manager.delete(
        obj_or_pk=1,
        expected_status=204,
    )



if __name__ == "__main__":
    asyncio.run(main())

Status

0.0.5 - RELEASED

Licence

Resty-Client is released under the MIT License. See the bundled LICENSE file for details.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc