Python module for communicating with an API built with Reflect over HTTP or UNIX sockets
Find a file
2023-05-01 17:55:47 +02:00
src feat: add pypi package 2023-05-01 17:17:19 +02:00
.gitignore feat: add pypi package 2023-05-01 17:17:19 +02:00
LICENSE initial commit 2023-05-01 15:15:20 +02:00
README.md feat(doc): add doc for Python lib 2023-05-01 17:55:47 +02:00
requirements.txt feat: add pypi package 2023-05-01 17:17:19 +02:00
setup.py feat: add pypi package 2023-05-01 17:17:19 +02:00

Reflect API client for Python

Make requests to an API built using the Reflect API framework over HTTP or UNIX sockets.


Make a request with Client.call(). It will always return the response as a tuple of length 2.

  • The first value is the HTTP-equivalent response code.
  • The second value is the response body
client = Client("<API URL or path to UNIX socket>", "<Optional API key>");

client.call("foo", Method.GET) # (tuple) (200, "bar")
client.call("foo", Method.POST, {
  "hello": "world
}) # (tuple) (201, "Created")

# etc..

How to use

Requires Python 3 or newer, and of course a Reflect API endpoint.

  1. Install with pip

    pip3 install reflect-client
    
  2. Initialize the module

    from reflect-client import Client 
    
    client = Client("<API URL or path to UNIX socket>", "<Optional API key>");
    
  3. Make API request

    Use the call() method to perform a request

    client.call("foo?bar=baz", Method.GET);
    
    Argument index Type Required Description
    0 String Yes Fully qualified pathname and query params of the endpoint to call
    1 Method Yes A supported Reflect HTTP method (eg. Method::GET)
    2 List No An optional List of key and values to be sent as Content-Type: application/json to the endpoint

    The call() function will return an array of length 2 wil the following information

    Index Type Description
    0 Int HTTP-equivalent response code (eg. 200 or 404)
    1 String/Array Contains the response body as either a string, or array if the response Content-Type header is application/json