Skip to main content

fastapi-repl

Django's shell_plus, for FastAPI. One command opens an interactive shell with your models, database engine, session and favourite imports already loaded, and top-level await that just works with async drivers.

$ fastapi-repl
╭──────────────────────────────────────────────────────────────────────────────────╮
│ fastapi-repl 0.1.0  Python 3.12.11 · IPython 9.5.0 · SQLAlchemy 2.0.54 (async)   │
│ Project: /home/me/code/my-api                                                    │
│                                                                                  │
│ ORM helpers  select, insert, update, delete, func, text, and_, or_, not_, desc,  │
│              asc, case, cast, literal, exists, selectinload, joinedload, ...     │
│ Models (12)  User, Account, Post, Comment, Tag, Subscription, ...                │
│ Objects      app (FastAPI), engine (AsyncEngine), session (AsyncSession)         │
│ Imports      settings                                                            │
│                                                                                  │
│ Top-level await is on, try: (await session.scalars(select(User).limit(5))).all() │
╰──────────────────────────────────────────────────────────────────────────────────╯

In [1]: user = await session.scalar(select(User).where(User.email == "ada@example.com"))

FastAPI has no built-in shell, so every project ends up with a half-working python -i script. fastapi-repl replaces that script with something you can configure and reuse across projects.

  • ORM agnostic. SQLAlchemy (sync and async), SQLModel and Tortoise ORM work out of the box. Any other ORM can be supported with a small adapter class.
  • Top-level await in IPython, ptpython, ptipython and the plain Python shell, all running on one shared event loop so async connection pools keep working between lines.
  • Auto-imports every model, plus helpers like select, func, selectinload or Q, F, Count, plus anything you add. Name collisions are handled for you.
  • Your app, started. Optionally runs your ASGI lifespan so startup code (connection pools, caches, Tortoise's RegisterTortoise...) is live in the shell.
  • Everything shell_plus does: --print-sql, -c, piped stdin, scripts, Jupyter notebooks, --dont-load, model aliases, pre/post imports, PYTHONSTARTUP...
  • Works with any ASGI framework: FastAPI, Starlette, Litestar, or no framework at all.
  • Configured in pyproject.toml, overridable by environment variables and flags, with fastapi-repl config showing where each value came from.

fastapi-repl is an independent project and is not affiliated with FastAPI.

Install

pip install "fastapi-repl[ipython]"      # or: uv add --dev "fastapi-repl[ipython]"

The extras are optional: ipython, ptpython, bpython, jupyter, or all. Without any of them you get the plain Python shell, still with top-level await. Python 3.11+ is required.

Quick start

$ fastapi-repl init        # detects your app, models, engine and session factory
$ fastapi-repl             # start the shell

init writes a config like this to pyproject.toml. You can also write it by hand:

[tool.fastapi-repl]
models = ["app.models"]
base = "app.db:Base"
env_file = ".env"
imports = ["from app.core.config import settings"]

[tool.fastapi-repl.sqlalchemy]
engine = "app.db:engine"
session_factory = "app.db:SessionLocal"

Then:

$ fastapi-repl --ptpython               # pick an interface
$ fastapi-repl --print-sql              # print every SQL statement
$ fastapi-repl -c "print(await session.scalar(select(func.count(User.id))))"
$ fastapi-repl run scripts/backfill.py  # run a script with everything loaded
$ fastapi-repl --lab                    # JupyterLab with a preloaded kernel
$ fastapi-repl imports                  # what gets loaded, and from where
$ fastapi-repl doctor                   # diagnose problems

Coming from Django?

Django / django-extensions fastapi-repl
manage.py shell_plus fastapi-repl
shell_plus --ipython / --ptpython fastapi-repl --ipython / --ptpython
shell_plus --print-sql fastapi-repl --print-sql
shell -c "..." fastapi-repl -c "..." (with await)
shell_plus --notebook / --lab fastapi-repl --notebook / --lab
runscript fastapi-repl run
SHELL_PLUS_PRE_IMPORTS pre_imports
SHELL_PLUS_MODEL_ALIASES model_aliases
SHELL_PLUS_DONT_LOAD dont_load

See the full migration guide.

Documentation

Contributing

Bug reports and pull requests are welcome. See CONTRIBUTING.md to get a development environment running in a minute.

License

MIT

Release files for fastapi-repl 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-repl 0.1.0
File Size Uploaded
fastapi_repl-0.1.0.tar.gz 92.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-repl 0.1.0
File Interpreter ABI Platform
fastapi_repl-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 155.9 kB

Release files / fastapi_repl-0.1.0.tar.gz

Download URL fastapi_repl-0.1.0.tar.gz
Size 92.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ef9825cfef8a9c188806ebc1aac415a3b15ea4e40da49a669b8802b52f78843c
BLAKE2b-256 checksum
How to use checksums
0e400588e28b5b381bfaf66ee02a0b86b79b00e8947f29cfa8c267dbea65a9d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

Release files / fastapi_repl-0.1.0-py3-none-any.whl

Download URL fastapi_repl-0.1.0-py3-none-any.whl
Size 63.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81df28aa0245318c23f0d4af4ad5c93d2adc660533f17f2b276a9ad2a1d839f0
BLAKE2b-256 checksum
How to use checksums
49d6bce0f3d46857b887d0ae42e70bc2955fff6c68faec0d4278b4303856a439
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page