Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Small, opinionated library for building REST APIs.

Project description


Apian is an opinionated library for setting up a Python-based service with a minimum of boilerplate. It is a thin wrapper around flask-restplus and provides:

  • Documentation using OpenAPI.
  • Info and health resources.
  • JWT-based authentication.
  • Configuration injection using miniscule.


Add a configuration file config.yaml in the root of the project, with the following contents:

environment: production
debug: False
  enabled: True
  secret: secret

To create a Flask application and run it on localhost:5000:

from apian import read_config, create_api, create_app, authenticated
from flask_restplus import Namespace, Resource

ns = Namespace("user")

class UserItem(Resource):

    def get(self, user_id):
        return user_id

config = read_config()
api = create_app("my-app", config)
app = create_app(api, config)

The application has endpoints at the paths:

  • GET /my-app/api/info - Return information about the service.
  • GET /my-app/api/health - Return the health status of the service.
  • GET /my-app/api/user - Return the user ID set in the Bearer token.

To access the user resource, ensure that the requests package is installed and execute the following snippet:

import jwt
import requests

def auth_token():
  user_id = 10
  claims = {"iat": dt.datetime.utcnow(), "sub": user_id}
  key = "secret"
  return jwt.encode(claims, key, "HS256")

headers = {"Authorization": "Bearer {}".format(
requests.get("http://localhost:5000/my-app/api/user", headers=headers)

Project details

Download files

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

Files for apian, version 0.5.0
Filename, size File type Python version Upload date Hashes
Filename, size apian-0.5.0.tar.gz (5.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page