Running Flask?

Legacy Flask app slow, insecure or unowned? We unstick it.

A lot of Flask apps that reach us were written in a hurry by a founder or a single engineer, grew organically, and then stayed in production for a decade. The Python interpreter is old, the dependencies are pinned to versions pip warns about, and nobody is quite sure which endpoints still get traffic. We work through it, upgrade what can be upgraded, document what cannot, and leave you with something a modern team can actually maintain.

  • Since 2015Fixing technology
  • FreeEstimates
  • US teamReal engineers

flask-gunicorn.log

still failing

What it is

Flask at a glance

Flask is a Python micro-framework for the web, created by Armin Ronacher in 2010. It is intentionally small, sitting on top of the Werkzeug WSGI toolkit and the Jinja2 template engine, with the philosophy that you add only the pieces your app actually needs. Its minimal core and clear request/response model made it the default pick for a long stretch of Python web development.

The Pallets Projects maintains Flask alongside Werkzeug, Jinja, Click and itsdangerous. Flask 2.0 added async view support, and Flask 3 tightened the extension story and dropped older Python versions. Typical production setups put gunicorn or uWSGI in front of a Flask app, SQLAlchemy for the ORM, Flask-Migrate (Alembic) for schema changes, and Redis for background jobs with RQ or Celery.

Type
Python WSGI micro-framework
First released
April 2010
License
BSD-3-Clause
Maintained by
The Pallets Projects
Typically used for
Internal tools, APIs, admin panels, small to medium web apps, prototype services, scientific and data-team web interfaces

The honest version

Flask pros and cons

No technology is all upside. This is where Flask earns its place and where it tends to cause trouble.

Where Flask is strong

  • Small and readableA Flask app can start as a single file with ten lines, and that same file scales to a real service without the framework imposing much structure you did not choose.
  • You pick the stackORM, migrations, auth, forms, admin, async work and task queues are all library choices rather than framework mandates. Nothing is forced on you.
  • Great for internal tools and APIsA small REST or JSON API with SQLAlchemy and Flask-RESTX can ship in a day, and typically does what the team actually needs without heavy ceremony.
  • Mature and stableFifteen years of production use have shaken out most surprises. The behavior of request context, blueprints and extensions is well understood.
  • Huge extension catalogFlask-Login, Flask-SQLAlchemy, Flask-Migrate, Flask-WTF, Flask-Admin and dozens more cover the common needs without rewriting the basics.
  • Easy to hostAny WSGI host runs it: gunicorn, uWSGI, mod_wsgi on Apache, Passenger, serverless wrappers, or a plain systemd unit on a Linux box. No special runtime required.

Where Flask bites

  • Minimalism becomes inconsistency over timeBecause Flask does not prescribe structure, projects drift. One blueprint uses class-based views, another uses function views, a third has helper modules that import across contexts, and refactoring costs climb with age.
  • Async support is partialFlask 2 added async views but the underlying WSGI model is still synchronous at its core. True async workloads are often better served by FastAPI or Quart.
  • Request context errors are confusing`RuntimeError: Working outside of application context` is one of the most common Flask stack traces. Background jobs, test fixtures and initialization code all hit it in different ways.
  • SQLAlchemy sessions require careA Flask-SQLAlchemy session that is not cleanly scoped to a request can hold stale data, leak connections or block transactions under load, and the debugging is not obvious.
  • Extensions can lag Flask releasesAn upgrade to Flask 3 or Werkzeug 3 often means running down a chain of extensions that have not been maintained, or writing the shim yourself.
  • Security defaults are up to youCSRF, CORS, secure cookies, rate limiting and secret handling are not configured out of the box. A Flask app with defaults is not a production-ready app.

Sound familiar?

Common Flask problems we fix

The Flask problems that bring people to us, and what you have once each one is fixed.

cannot import name 'url_quote' from 'werkzeug.urls'

The Werkzeug 3 upgrade broke imports

Werkzeug 3 moved or removed several helpers that older Flask and extension code reached into directly. Pinning stops the bleed, upgrading fixes it properly.

Running on current Werkzeug and Flask

Python 3.7 EOL · still in production

The runtime is past end-of-life

A Flask app on Python 2 or Python 3.7, picking up no security fixes, with dependencies that cannot be upgraded further on the old interpreter.

On a supported Python with tests green

RuntimeError: Working outside of application context

Background jobs cannot access the database

A Celery or RQ worker trying to use Flask-SQLAlchemy without pushing an app context, so every ORM call dies before touching the database.

Context handled, workers happy

no handover docs, no owner

We inherited a Flask app and nobody knows it

An app built by a founder or former contractor, running on a server with SSH keys half-rotated, and a requirements.txt nobody has updated in five years.

App documented and under your control

WORKER TIMEOUT pid:4821

Gunicorn is killing requests

A slow database query, a synchronous call to a third-party API with no timeout, or an N+1 ORM query running inside a request past the gunicorn timeout.

Requests complete within the budget

SQLAlchemy InvalidRequestError

SQLAlchemy sessions are getting wedged

An unhandled exception leaving the session in a rolled-back state, a session reused across threads, or long-lived sessions that have not been disposed of.

Sessions clean, scoped per request

SECRET_KEY not set, using default

Security basics are missing

Development defaults running in production, no CSRF on forms, cookies without Secure or HttpOnly, and no CORS policy, which together make the app fail a basic audit.

Production-grade defaults applied

pip install -r requirements.txt · 47 warnings

The dependency tree is rotting

Pinned versions three to six years old, conflicting transitive deps, and a resolver that cannot produce a clean install on a modern Python.

Dependencies clean and installable

What we do

Flask help, from rescue to steady state

Hand us one failing endpoint, or the whole Flask codebase.

Legacy rescue
An old Flask app on an unsupported Python, with broken deploys and no one who remembers how it was built. We stabilize, document, and modernize in a sensible order.
Python and Flask upgrades
Moving from Python 2 or 3.7 up to a supported interpreter, from older Flask to Flask 3, and from legacy Werkzeug to current, with the test suite still passing.
SQLAlchemy and performance
Session scoping, N+1 fixes, connection pooling, slow-query audits and migration planning so the app survives real traffic rather than idealized dev traffic.
Security hardening
CSRF, CORS, secrets, rate limiting, secure cookies, auth review, and dependency vulnerability scanning so the app is defensible, not merely functional.
Handover and takeover
A Flask app owned by a former developer brought under your accounts, your repo, your hosting, with onboarding documentation good enough for a new engineer on day one.
Managed Tech
Dependency watch, Python version planning, log and uptime monitoring, security patches, and someone to call when gunicorn starts timing out under load.

How it works

From first message to fixed

  1. Look Free estimate

    Tell us what's going wrong. We look at it, then tell you plainly what's wrong and what it will cost.

  2. Fix

    We fix the cause, not the symptom. If something is down, getting it back up comes first.

  3. Harden

    Backups, monitoring, updates and access, so the same problem can't quietly come back.

  4. Hand back or stay on

    You get a plain-language write-up. Or we stay on for hosting, upkeep and new work.

Often found together

Running Flask alongside something else?

We work on the whole stack, so the problem can be wherever it actually is.

Questions

Flask questions

Something else? Call+1 737 727 7327

Can you upgrade a Flask app that is still on Python 2?

Yes, and it is one of the most common rescue jobs we see. The plan depends on what the app actually uses. In most cases it is: lock the current behavior under tests, port step by step to Python 3 and current Werkzeug, update SQLAlchemy and the extension set, and finally move the hosting to a supported runtime. We aim for parity first, improvements second.

Should we migrate from Flask to FastAPI?

Sometimes, but not always. If the app is sync HTTP with a mature extension footprint, moving to FastAPI for its own sake is often more cost than benefit. If the app is API-only, uses async-heavy I/O, or needs OpenAPI generation and better type ergonomics, FastAPI pays back the migration. We will tell you plainly which case you are in.

Why do we get 'Working outside of application context' errors?

This almost always comes from code running outside a request or without `app.app_context()`. The common culprits are background workers (Celery, RQ) that did not wrap their task in a context, test fixtures that import extensions eagerly, and scripts that import Flask-SQLAlchemy models before the app is initialized. The fix is explicit context handling in the right places.

Can you take over a Flask app a previous developer wrote?

Yes, this is a large share of what we do. We inventory routes, blueprints, extensions and infra, bring credentials and deployment into your accounts, pin the dependency tree, and leave you with a repo and a runbook. From that point we either keep maintaining it or hand it to your internal team.

How do we make our Flask app faster?

Almost always by fixing database access first. N+1 queries, missing indexes, large result sets loaded into memory and sessions held open across slow I/O are the real causes of slow Flask apps, far more than framework overhead. We profile the real traffic, fix the hot path, and only then look at workers and caching.

How much does Flask help cost?

A quote costs nothing. Share the repo link or a note on what is broken, and a price arrives before any engineer begins work.

Free estimate

Flask app giving you trouble?

Tell us what you're running and what's going wrong. A person reads it and comes back with an estimate.

  • No charge to find out what it will take
  • If it's urgent, say so

Replies come from a person. By sending, you authorize us to email you back. No marketing.