Tooling to assist with building Flask APIs
Project description
Flask API Tools
Utilities for building, running, and maintaining Python APIs with Flask and associated Flask extensions.
Installation
Install and update using pip
:
pip install -U Flask-API-Tools
Storage Backed Rate Limiting
The InMemoryLimiter
class is an extension of Flask-Limiter. This class
implements storage-backed rate limiting. You'll need to follow the rate limiting steps
outlined in Flask-Limiter, and
you must provide a RATELIMIT_STORAGE_URL
to a redis (or other in-memory data
structure) instance.
This class attaches any existing Flask log handlers to Flask-Limiter.
Basic Flask usage:
from flask import Flask
from flask_api_tools.rate_limiting.in_memory_limiter import InMemoryLimiter
app = Flask(__name__)
limiter = InMemoryLimiter(app=app, storage_uri="redis://localhost:6379")
This will raise a ConfigurationError
(from limits.errors
) if the backend
storage is inaccessible.
Alternatively, you can still benefit from the configuration checking when using
Flask-Limiter's init_app
function:
from flask import Flask
from flask_api_tools.rate_limiting.in_memory_limiter import InMemoryLimiter
app = Flask(__name__)
limiter = InMemoryLimiter(storage_uri="redis://localhost:6379")
# Do some other things with the limiter...
limiter.init_app(app=app)
Developing
The build pipeline requires your tests to pass and code to be formatted
Make sure you have Python 3.x installed on your machine (use pyenv).
Install the dependencies with pipenv (making sure to include dev and pre-release packages):
pipenv install --dev --pre
Configure your environment:
pipenv shell && export PYTHONPATH="$PWD"
Run the tests:
pytest
Or with logging:
pytest -s
Or tests with coverage:
pytest --cov=./
Format the code with Black:
black $PWD
Releases
Cleanup the (.gitignored) dist
folder (if you have one):
rm -rf dist
Notch up the version number in setup.py
and build:
python3 setup.py sdist bdist_wheel
Push to PyPi (using the ScholarPack credentials when prompted)
python3 -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
Links
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.
Source Distribution
Built Distribution
Hashes for flask_api_tools-1.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2fd2a8366d261fe2a449eca916840dd5405d5a5adc530230717f9aabb80c461 |
|
MD5 | cab6c9d7332f5153b72d7566231863c9 |
|
BLAKE2b-256 | ff1dfa0365bc6f2ba7c43c3dd8c6c96e28b0f4045261e4d227c8218b876ff604 |