Aidbox SDK for python
Project description
aidbox-python-sdk
- Create a python 3.9+ environment
pyenv
- Set env variables and activate virtual environment
source activate_settings.sh
- Install the required packages with
pipenv install --dev
- Make sure the app's settings are configured correctly (see
activate_settings.sh
andaidbox_python_sdk/settings.py
). You can also use environment variables to define sensitive settings, eg. DB connection variables (see example.env-ptl
) - You can then run example with
python example.py
.
Getting started
Minimal application
from aidbox_python_sdk.main import create_app as _create_app
from aidbox_python_sdk.settings import Settings
from aidbox_python_sdk.sdk import SDK
settings = Settings(**{})
sdk = SDK(settings, resources=resources, seeds=seeds)
async def create_app():
return await _create_app(sdk)
Register handler for operation
import logging
from aiohttp import web
from yourappfolder import sdk
@sdk.operation(
methods=["POST", "PATCH"],
path=["signup", "register", {"name": "date"}, {"name": "test"}],
timeout=60000 ## Optional parameter to set a custom timeout for operation in milliseconds
)
def signup_register_op(operation, request):
"""
POST /signup/register/21.02.19/testvalue
PATCH /signup/register/22.02.19/patchtestvalue
"""
logging.debug("`signup_register_op` operation handler")
logging.debug("Operation data: %s", operation)
logging.debug("Request: %s", request)
return web.json_response({"success": "Ok", "request": request["route-params"]})
Validate request
schema = {
"required": ["params", "resource"],
"properties": {
"params": {
"type": "object",
"required": ["abc", "location"],
"properties": {"abc": {"type": "string"}, "location": {"type": "string"}},
"additionalProperties": False,
},
"resource": {
"type": "object",
"required": ["organizationType", "employeesCount"],
"properties": {
"organizationType": {"type": "string", "enum": ["profit", "non-profit"]},
"employeesCount": {"type": "number"},
},
"additionalProperties": False,
},
},
}
@sdk.operation(["POST"], ["Organization", {"name": "id"}, "$update"], request_schema=schema)
async def update_organization_handler(operation, request):
location = request["params"]["location"]
return web.json_response({"location": location})
Valid request example
POST /Organization/org-1/$update?abc=xyz&location=us
organizationType: non-profit
employeesCount: 10
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aidbox_python_sdk-0.1.9.tar.gz
(16.0 kB
view hashes)
Built Distribution
Close
Hashes for aidbox_python_sdk-0.1.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b881297128239684ec0f33e445a13fac2a8b7faa4fad5777a32082b3304b35eb |
|
MD5 | e44dcdb9679896f9f1097cd239080b2d |
|
BLAKE2b-256 | 52a56c6e9f53f04bf8e8c7c5dae059ee63a69c5bc82ecf0e4ebadeaafc31e80b |