Skip to main content

Provide helper for REST API related stuff.

Project description

Layab: Wonderful REST API

pypi version Build status Coverage Code style: black Number of tests Number of downloads

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

  1. python 3.6+ must be installed
  2. Use pip to install module:
python -m pip install layab

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

layab-1.6.0.tar.gz (10.3 kB view hashes)

Uploaded Source

Built Distribution

layab-1.6.0-py3-none-any.whl (11.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page