skillfed

Flask-Threads

A helper library to work with threads within Flask applications.

flask-threads v0.2.0 999.5K downloads/30d#4,540 on PyPI29
License unclear Active released

What it is and what it does

Flask-Threads solves a core problem when running background work in Flask: the application context is thread-local, so spawning a new thread normally causes an exception when that thread tries to access flask.g or other context-bound objects. This library wraps threading and concurrent.futures modules to carry the Flask application context into background threads, letting you safely read and write context data from worker threads.

The package provides helper classes that capture the current Flask context and push it into worker threads before execution. It depends only on Flask and is straightforward to integrate into existing Flask applications for background task patterns.

Use it for:

  • Run background tasks (logging, cleanup, notifications) from a request handler while accessing request-specific data stored in flask.g.
  • Submit multiple worker tasks to a thread pool from within a Flask route, each task able to read application or request context.
  • Offload long-running work to a background thread without losing access to database sessions or user context stored in flask.g.
  • Implement worker patterns where context-aware cleanup or finalization must happen in a separate thread.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides thread and thread pool helpers that preserve Flask application context, allowing background threads to safely access flask.g and other context-local data.

Yes, with conditions. Install if you need to run background threads in Flask and must access application context from those threads. The package solves a real Flask threading problem with low install friction and no known vulnerabilities. However, verify the license before production use, and be aware that adoption is limited (29 stars), so community support and edge-case testing are minimal.

Install

flask-threads on PyPI

pip

pip install flask-threads

uv

uv add flask-threads

poetry

poetry add flask-threads

Installing Flask-Threads

Before you install

Low friction install with a single runtime dependency on Flask. The package is actively maintained with a recent release in May 2025 and regular commits; however, the small repository size (29 stars) suggests limited real-world adoption and testing.

License in practice

License status is unclear—no SPDX identifier or raw license text is declared in the package metadata. Before using in production or proprietary code, verify the actual license by checking the repository directly.

Quickstart

pip install Flask-Threads

from flask import Flask, g

app = Flask(__name__)

@app.route('/task')
def run_task():
    g.data = 'value'
    return 'done'

Verify before relying

  • Whether the package works with all modern Flask versions or has specific version constraints.
  • Real-world performance and thread safety characteristics under concurrent load.
  • Whether the thread pool executor properly handles exceptions and cleanup in all scenarios.
  • Specific API and usage patterns beyond the description excerpt provided.

Package facts

License not declared (unclear)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 1 — Flask
Maintenance actively maintained — 451 days since the last release
Last repo commit
First released
Downloads 999,453/month — #4,540 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: flask_threads-0.2.0-py3-none-any.whl

Tags

flask background threadsflask application context threadingflask thread pool executorflask concurrent futuresflask thread local contextflask threaded workers
flask-extensionthreadingcontext-management

More Application Frameworks packages