Provide helper for REST API related stuff.
Project description
Layab: Wonderful REST API
Layab stands for Wonderful
in Somali and is also a shortcut for Layabout
(aren't we all lazy).
This package provides helper functions on top of Flask-RestPlus to create standardized REST API.
Available features
API
You can create a Flask application and a Flask-RestPlus API using the layab.create_api
function.
import layab
application, api = layab.create_api(
__file__,
title="My API",
description="This is the purpose of my API",
)
Monitoring
Importing layab will make sure that every flask request is logged as INFO upon reception and return (even in case an exception occurred).
import layab
You can add monitoring endpoints to your API using layab.add_monitoring_namespace
function.
The following endpoints will then be available:
/health
: Providing Health of your API/changelog
: Providing the changelog of your application so that clients can check what's new.
import layab
api = None # Replace with your Flask-RestPlus API instance
def health_details():
# Health status, Health details
return "pass", {}
layab.add_monitoring_namespace(api, health_details)
Should you need to check the status of an external HTTP service or a Redis connection, you can rely on healthpy to retrieve the health status and details.
Note that healthpy also handle the merging of multiple status into one.
Configuration
API and logging configuration should be stored in YAML format.
import layab
# Load logging and service configuration
service_configuration = layab.load('path/to/a/file/in/module/folder')
Note that in case your logging configuration file contains execution of Python code, you will need to provide the yaml.UnsafeLoader
loader.
import layab
import yaml
# Load logging and service configuration
service_configuration = layab.load('path/to/a/file/in/module/folder', logging_loader=yaml.UnsafeLoader)
How to install
- python 3.6+ must be installed
- Use pip to install module:
python -m pip install layab
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.