Aidbox SDK for python
Project description
aidbox-python-sdk
- Create a python 3.8+ 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
.
Add APP_FAST_START_MODE=TRUE
to env_tests for fast start mode.
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.3.tar.gz
(15.8 kB
view hashes)
Built Distribution
Close
Hashes for aidbox_python_sdk-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ddfff04292519f791a9ec81ff5d2fdf17a14c92fc178bc9bd0ec4ad73da5d6c |
|
MD5 | fa940f7b0e8230286a8bf985098b724a |
|
BLAKE2b-256 | 7167507f31f3cd40e86a96af7d3e8595cbf65e12015f90d45e1a2bfc0d1a915f |