Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
/ flask-utils Public archive

Various Flask utilities that I find useful in my projects

License

Notifications You must be signed in to change notification settings

Seluj78/flask-utils

Repository files navigation

This project is archived

I've moved on to using FastAPI in my new company, and I don't feel the need to maintain this anymore

Documentation Status GitHub commit activity GitHub commits since latest release GitHub Actions Workflow Status GitHub Actions Workflow Status GitHub License All Contributors codecov

Flask-Utils

A collection of useful Flask utilities I use every day in my Flask projects.

Installation

pip install flask-utils

Usage

from flask import Flask
from flask_utils import FlaskUtils
from flask_utils import BadRequestError

app = Flask(__name__)
utils = FlaskUtils(app, register_error_handlers=True)

@app.route('/')
def index():
    raise BadRequestError
from typing import List, Optional
from flask import Flask
from flask_utils import validate_params

app = Flask(__name__)

@app.post('/create-user')
@validate_params({"first_name": str, "last_name": str, "age": Optional[int], "hobbies": List[str]})
def create_user():
    # ...
    # This will enforce the following rules:
    # - first_name and last_name must be strings and are required
    # - age is optional and must be an integer
    # - hobbies is a list of strings
    # This is just an example, you can use any type of validation you want
    return "User created"

Documentation

You can find the full documentation at Read the Docs

Testing

Install uv

curl -LsSf https://astral.sh/uv/install.sh | sh

Run the tests

uv run tox

OR

Run the tests in a multithreaded fashion

uv run tox -p

Contributors

Jules Lasne
Jules Lasne

💻 📖 🚇 💡 🧑‍🏫 📦 📆 👀
Mews
Mews

📖
Julien Palard
Julien Palard

🤔
Add your contributions