Skip to main content

Web framework for the serverless domain

Project description

circle pypi version apache license

Using AWS lambda functions and API Gateway, minik will serve as the framework that facilitates development in the serverless space.

Installing

Install the latest release:

>>> pip install minik
✨🍰✨

Only Python 3.6+ is supported.

Simple Example

In it’s most basic form; quite honestly, it’s only form. This is how your lambda function should look like:

from minik.core import Minik, BadRequestError

app = Minik()

@app.route('/hello/{name}')
def hello_view(name):

    if name == 'FINDME':
        # Returns a 400 status code with the message as the body.
        raise BadRequestError(msg='This is not a supported name.')

    # A simple way of getting the current request as json.
    request_payload = app.request.json_body
    return {'hello': name}

HTTP Methods

With minik you can also specify the HTTP methods for a given view. If you don’t define the methods, every single HTTP method will be allowed by default.

from minik.core import Minik

app = Minik()

@app.route('/events/{location}')
def events_view(location):
    # This route will be invoked for GET, POST, PUT, DELETE...
    return {'data': ['granfondo MD', 'Silver Spring Century']}

@app.route('/events', methods=['POST', 'PUT'])
def create_event_view():
    create_event(app.request.json_body)
    return {'result': 'complete'}

Route Parameter Validation

Minik uses function annotations to validate the value of a route. If the type of an expected parameter is not valid, minik will respond with a 404 not found status code.

@app.route('/articles/{author}/{year}/')
def get_articles_view(author: str, year: int):
    # Type conversion: isinstance(author, str) and isinstance(year, int)
    return {'author_name': author, 'year': year}

To learn more checkout out the route validation page.

Motivation

The team behind this framework is adopting a very minimal set of features to enhance and streamline web development in the serverless space. These were the business needs that encouraged us to build minik:

  • Ability to write an API using a familiar (Flask like) syntax using serverless services.

  • Flexibility on how to build and deploy lambda functions. I do not want my framework to dictate these processes for me. I want to own them!

  • When installing a web framework, I want to get only the framework. I don’t want any additional tooling or any additional process-based workflows.

  • When using the microframework I am responsible for the configuration required to associate my lambda function to its endpoints.

The features of this library should be absolutely driven by a very specific business need. So far, the minimal approach has been sufficient for our team to write and expose an API using AWS services.

Just the framework

Things to be aware of when working using minik:

  • When used in your lambda function, you’re responsible for including the source code of minik in your .zip artifact. For packaging purposes we recommend using Juniper.

  • Unlike other frameworks like Flask or Django, where using the decorator is sufficient to define the routes of the web app, in minik, you’re responsible for linking a lambda function to the API gateway. We recommend using a SAM template.

  • Minik does not include a local development server! For testing purposes, you can either deploy your lambda to AWS using sam package and sam deploy. For local deployment purposes you can use sam local.

Quickstart

Minik is just one of the pieces that you need to build serverless APIs. If you are curious to learn more about best practices and how to get started with this microframework, checkout out getting started guide.

The quickstart uses a very simple example, which is included in this codebase, as a way to highlight the benefits of the framework.

Contributing

For guidance on setting up a development environment and how to make a contribution to Minik, see the contributing guidelines.

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

minik-0.3.1.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

minik-0.3.1-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file minik-0.3.1.tar.gz.

File metadata

  • Download URL: minik-0.3.1.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.5

File hashes

Hashes for minik-0.3.1.tar.gz
Algorithm Hash digest
SHA256 8de0566137e4475354987f9c2a3ea4232f62184dff8004d3757201401f6ef82f
MD5 072ed64ffe5bc6e5227c22189da1b127
BLAKE2b-256 ed5773e593487b2081cfc99fc2f67392171e84e03466389d8076ae225f733d07

See more details on using hashes here.

File details

Details for the file minik-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: minik-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.5

File hashes

Hashes for minik-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9a0564abe58b5c8a8dba8636f45aa7b2dba5bca4946eb67f94f7c773f7a59577
MD5 f077b2c110e798500c7c6d5ad53e1873
BLAKE2b-256 d21ad37d72f85e1315bba1db577e99dd9f108088eb84ebd9f5a33339820de8ec

See more details on using hashes here.

Supported by

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