Skip to main content

A

Project description

Python Rest API Client (WIP)

Work in progress. Aims at glueing pydantic and httpx with a simple REST API client, with dynamic generated methods. Ideally, it could be support both synchronous and asynchronous formats.

Currently it is only supporting GET Methods, since it's a work in progress. Roadmap:

  • Support POST, PUT, PATCH, DELETE
  • Adds Authentication support
  • Adds Async invokation support
  • Export generated source code
  • Auto generate models from OpenAPI (3) Spec

Usage

CHUCK_BASE_URL = "https://api.chucknorris.io/jokes"

# Imports
from pydantic import BaseModel, HttpUrl
from rest_api_client.lib import RestAPI, Endpoint, HTTPMethod
import httpx

# Optionally declare your model classes
class JokeModel(BaseModel):
    id: str
    created_at: str
    updated_at: str
    icon_url: str
    categories: list
    url: str
    value: str


# Declare your API endpoints

endpoints = [

    # Fully descriptive declaration.
    Endpoint(
        name="get_joke",
        path="/random",
        method=HTTPMethod.GET,
        model=JokeModel,
        query_parameters=[("category", str)],
    ),

    # No model provided, result comes back as a dictionary.
    Endpoint(
        name="get_categories",
        path="/categories",
        method=HTTPMethod.GET,
    ),
    
    # Omit HTTP Method, it gets inferred from the endpoint name.
    Endpoint(name="get_search", path="/search", query_parameters=[("query", str)]),
]

# Instantiate your HTTP client session. Should also work with requests

with httpx.Client() as client:
    api = RestAPI(api_url=CHUCK_BASE_URL, driver=client)
    api.register_endpoints(endpoints)

    joke = api.call_endpoint("get_joke")
    joke2 = api.get_joke()

    categories = api.get_categoires()

    search = api.get_search(query="something")

    print(joke)
    print(joke2)
    print(search)

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

py-rest-api-client-0.0.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

py_rest_api_client-0.0.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file py-rest-api-client-0.0.2.tar.gz.

File metadata

  • Download URL: py-rest-api-client-0.0.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2

File hashes

Hashes for py-rest-api-client-0.0.2.tar.gz
Algorithm Hash digest
SHA256 88f70904cff10a098360e8ac6782a65ed8a3a181cda3cb499d4f0ac02fcfb4dd
MD5 247795917de2a1bd2fdf58d0b8d3f43a
BLAKE2b-256 e2bf5d7812783f64df0b548f4a09664435c45a43e15d2eb1d58f45a84d12415c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_rest_api_client-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2

File hashes

Hashes for py_rest_api_client-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4bfa82fdeccaf435dc50e196e97d2788f2951230224ff5ca81a2a0cf794d827c
MD5 d8d0dba380e3d88f03a01c270bf40fbb
BLAKE2b-256 cd0cb04d9beab0441527566ad7e6e7eff3a8c67c683ec9e221c59d705c287199

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page