The flask Package

The flask package provides a micro-framework for making web applications and APIs.

References

Installation

First install flask, if necessary:

pip install flask

Usage

Follow the "Web Application" Exercise for an introduction to making web applications with Flask.

Testing

Testing Flask APIs:

import pytest

from api import create_app

@pytest.fixture
def api_client():
    app = create_app()
    return app.test_client()

def test_my_endpoint(api_client):
    response = api_client.get("/api/v1/my_endpoint")
    parsed_response = json.loads(response.data)
    assert response.status_code == 200
    assert isinstance(parsed_response, list)
    # etc.

Last updated