Python .gitignore Template

The full, current Python .gitignore template — copy it as-is, or head to the .gitignore Generator to merge it with other stacks into one file.

Template

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
#   Usually these files are written by a python script from a template
#   before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py.cover
*.lcov
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
#   For a library or package, you might want to ignore these files since the code is
#   intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
#   However, in case of collaboration, if having platform-specific dependencies or dependencies
#   having no cross-platform support, pipenv may install dependencies that don't work, or not
#   install all needed dependencies.
# Pipfile.lock

# UV
#   Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
#   This is especially recommended for binary packages to ensure reproducibility, and is more
#   commonly ignored for libraries.
# uv.lock

# poetry
#   Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
#   This is especially recommended for binary packages to ensure reproducibility, and is more
#   commonly ignored for libraries.
#   https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
# poetry.lock
# poetry.toml

# pdm
#   Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#   pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
#   https://pdm-project.org/en/latest/usage/project/#working-with-version-control
# pdm.lock
# pdm.toml
.pdm-python
.pdm-build/

# pixi
#   Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
# pixi.lock
#   Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
#   in the .venv directory. It is recommended not to include this directory in version control.
.pixi/*
!.pixi/config.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule*
celerybeat.pid

# Redis
*.rdb
*.aof
*.pid

# RabbitMQ
mnesia/
rabbitmq/
rabbitmq-data/

# ActiveMQ
activemq-data/

# SageMath parsed files
*.sage.py

# Environments
.env
.envrc
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
#   JetBrains specific template is maintained in a separate JetBrains.gitignore that can
#   be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
#   and can be added to the global gitignore or merged into this file.  For a more nuclear
#   option (not recommended) you can uncomment the following to ignore the entire idea folder.
# .idea/

# Abstra
#   Abstra is an AI-powered process automation framework.
#   Ignore directories containing user credentials, local state, and settings.
#   Learn more at https://abstra.io/docs
.abstra/

# Visual Studio Code
#   Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore 
#   that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
#   and can be added to the global gitignore or merged into this file. However, if you prefer, 
#   you could uncomment the following to ignore the entire vscode folder
# .vscode/
# Temporary file for partial code execution
tempCodeRunnerFile.py

# Ruff stuff:
.ruff_cache/

# PyPI configuration file
.pypirc

# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/

# Streamlit
.streamlit/secrets.toml

What each entry does

Why every line in this template is excluded, not just what it matches.

Entry Why it's excluded
__pycache__/ Python's compiled bytecode cache (.pyc files) — regenerated automatically and tied to the interpreter version that created it.
*.py[codz] Files matching *.py[codz] — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*$py.class Files matching *$py.class — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.so A compiled Linux shared library — build output.
.Python Files matching .Python — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
build/ Compiled/bundled output directory produced by the build tool — derived entirely from source, not source itself.
develop-eggs/ A generated/local directory (develop-eggs) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
dist/ The bundled, production-ready output a build step produces — regenerate it with the build command rather than committing it.
downloads/ A generated/local directory (downloads) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
eggs/ A generated/local directory (eggs) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.eggs/ A generated/local directory (.eggs) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
lib/ A generated/local directory (lib) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
lib64/ A generated/local directory (lib64) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
parts/ A generated/local directory (parts) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
sdist/ A generated/local directory (sdist) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
var/ A generated/local directory (var) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
wheels/ A generated/local directory (wheels) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
share/python-wheels/ A generated/local directory (share/python-wheels) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
*.egg-info/ Python packaging metadata generated by setuptools — regenerated on every build/install.
.installed.cfg Files matching .installed.cfg — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.egg Files matching *.egg — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
MANIFEST A generated/local directory (MANIFEST) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
*.manifest Files matching *.manifest — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.spec Files matching *.spec — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
pip-log.txt Files matching pip-log.txt — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
pip-delete-this-directory.txt Files matching pip-delete-this-directory.txt — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
htmlcov/ A generated/local directory (htmlcov) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.tox/ A generated/local directory (.tox) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.nox/ A generated/local directory (.nox) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.coverage Files matching .coverage — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
.coverage.* Files matching .coverage.* — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
.cache Files matching .cache — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
nosetests.xml Files matching nosetests.xml — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
coverage.xml Files matching coverage.xml — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.cover Files matching *.cover — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.py.cover Files matching *.py.cover — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.lcov A test-coverage report in lcov format — generated output, not source.
.hypothesis/ A generated/local directory (.hypothesis) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.pytest_cache/ pytest's cache of previous test results/failures — safe to regenerate, speeds up reruns only.
cover/ A generated/local directory (cover) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
*.mo Files matching *.mo — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.pot Files matching *.pot — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.log Runtime log output — grows unbounded, is different on every machine/run, and has no value in version control.
local_settings.py Files matching local_settings.py — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
db.sqlite3 Files matching db.sqlite3 — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
db.sqlite3-journal Files matching db.sqlite3-journal — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
instance/ A generated/local directory (instance) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.webassets-cache Files matching .webassets-cache — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
.scrapy Files matching .scrapy — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
docs/_build/ A generated/local directory (docs/_build) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.pybuilder/ A generated/local directory (.pybuilder) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
target/ Rust/Cargo's (and Maven's) build output directory — large, fully derived from source, and machine-specific.
.ipynb_checkpoints Files matching .ipynb_checkpoints — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
profile_default/ A generated/local directory (profile_default) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
ipython_config.py Files matching ipython_config.py — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
.pdm-python Files matching .pdm-python — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
.pdm-build/ A generated/local directory (.pdm-build) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.pixi/* Excludes .pixi/* — generated or machine-specific for this stack, not something to track in version control.
!.pixi/config.toml Re-includes .pixi/config.toml — carves out an exception to a broader exclusion pattern above it.
__pypackages__/ A generated/local directory (__pypackages__) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
celerybeat-schedule* Excludes celerybeat-schedule* — generated or machine-specific for this stack, not something to track in version control.
celerybeat.pid Files matching celerybeat.pid — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.rdb Files matching *.rdb — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.aof Files matching *.aof — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.pid A process-ID file a running dev server writes — pure runtime state, meaningless once the process exits.
mnesia/ A generated/local directory (mnesia) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
rabbitmq/ A generated/local directory (rabbitmq) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
rabbitmq-data/ A generated/local directory (rabbitmq-data) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
activemq-data/ A generated/local directory (activemq-data) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
*.sage.py Files matching *.sage.py — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
.env Local environment variables — routinely holds real secrets (API keys, DB passwords), so it must never be committed. Commit a .env.example instead.
.envrc Files matching .envrc — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
.venv A Python virtual environment (the other common folder name for it) — same reasoning as venv/.
env/ A generated/local directory (env) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
venv/ A Python virtual environment — a full copy of an interpreter plus installed packages; recreate it from requirements.txt/pyproject.toml instead of committing it.
ENV/ A generated/local directory (ENV) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
env.bak/ A generated/local directory (env.bak) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
venv.bak/ A generated/local directory (venv.bak) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.spyderproject Files matching .spyderproject — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
.spyproject Files matching .spyproject — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
.ropeproject Files matching .ropeproject — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
/site A generated/local directory (site) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.mypy_cache/ mypy's type-checking cache — purely a speed optimization, safe to delete/regenerate.
.dmypy.json Files matching .dmypy.json — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
dmypy.json Files matching dmypy.json — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
.pyre/ A generated/local directory (.pyre) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.pytype/ A generated/local directory (.pytype) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
cython_debug/ A generated/local directory (cython_debug) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.abstra/ A generated/local directory (.abstra) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
tempCodeRunnerFile.py Files matching tempCodeRunnerFile.py — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
.ruff_cache/ A generated/local directory (.ruff_cache) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.pypirc Files matching .pypirc — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
marimo/_static/ A generated/local directory (marimo/_static) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
marimo/_lsp/ A generated/local directory (marimo/_lsp) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
__marimo__/ A generated/local directory (__marimo__) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
.streamlit/secrets.toml Files matching .streamlit/secrets.toml — a generated or machine-specific file type for this stack, safe to regenerate rather than track.