mirror of
https://codeberg.org/reflect/reflect-client-python.git
synced 2025-11-05 04:32:41 +01:00
Python module for communicating with an API built with Reflect over HTTP or UNIX sockets
| reflect_client | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
| requirements.txt | ||
| setup.py | ||
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.
-
Install with pip
pip3 install reflect-client -
Initialize the module
from reflect-client import Client client = Client("<API URL or path to UNIX socket>", "<Optional API key>"); -
Make API request
Use the
call()method to perform a requestclient.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/jsonto the endpointThe
call()function will return an array of length 2 wil the following informationIndex Type Description 0 Int HTTP-equivalent response code (eg. 200or404)1 String/Array Contains the response body as either a string, or array if the response Content-Typeheader isapplication/json