.gitignore for Python

95 ignore rules for Python, ready to copy into your repository.

The Python programming language

The complete .gitignore for Python

# Generated by LFGitignore - https://lfgitignore.com
# Created: 2026-09-17 17:00:39 UTC
# Technologies: Python

### Python ###
# Python bytecode cache directory
__pycache__/
*.py[codz]
# Python/Jython class files
*$py.class
# IPython default profile
profile_default/
# Shared object
*.so
# IPython configuration
ipython_config.py
# Python version marker
.Python
# Build output directory
build/
# Python development eggs
develop-eggs/
# Distribution directory
dist/
# Downloaded files
downloads/
# Python egg packages
eggs/
# Python eggs directory
.eggs/
# Library directory
lib/
# 64-bit library directory
lib64/
# Buildout parts
parts/
# Python source distribution
sdist/
var/
# Python wheel packages
wheels/
# Shared Python wheels
share/python-wheels/
# Python package metadata
*.egg-info/
# Buildout installed config
.installed.cfg
# Python egg package
*.egg
# Python manifest file
MANIFEST
# Manifest files
*.manifest
# PyInstaller spec file
*.spec
# pip installation log
pip-log.txt
# pip marker file
pip-delete-this-directory.txt
# Coverage HTML report
htmlcov/
# tox test environments
.tox/
# nox test environments
.nox/
# Coverage data file
.coverage
# Coverage data files
.coverage.*
# Cache directory
.cache
# Nose test results
nosetests.xml
# Coverage XML report
coverage.xml
# Coverage annotated source
*.cover
*.py.cover
# LCOV coverage data
*.lcov
# Hypothesis test data
.hypothesis/
# pytest cache directory
.pytest_cache/
# Coverage reports
cover/
# Compiled message catalogs
*.mo
# Message catalog template
*.pot
# Log file
*.log
# Local Django settings
local_settings.py
# SQLite database
db.sqlite3
# SQLite journal
db.sqlite3-journal
# Flask instance folder
instance/
# Flask-Assets cache
.webassets-cache
# Scrapy cache
.scrapy
# Sphinx build output
docs/_build/
# PyBuilder directory
.pybuilder/
# Maven build directory
target/
# Jupyter notebook checkpoints
.ipynb_checkpoints
.pdm-python
.pdm-build/
.pixi/*
# PEP 582 packages
__pypackages__/
!.pixi/config.toml
# Celery beat PID file
celerybeat.pid
# Sage compiled files
*.sage.py
celerybeat-schedule*
# Environment variables
.env
*.rdb
.envrc
*.aof
# Python virtual environment
.venv
# Process ID file
*.pid
# Virtual environment directory
env/
mnesia/
# Virtual environment directory
venv/
rabbitmq/
# Environment backup
env.bak/
rabbitmq-data/
activemq-data/
# Virtual env backup
venv.bak/
# Spyder project
.spyderproject
# Spyder project settings
.spyproject
# Python rope refactoring
.ropeproject
/site
# mypy type checker cache
.mypy_cache/
# mypy daemon config
.dmypy.json
# mypy daemon config
dmypy.json
# Pyre type checker
.pyre/
# pytype static analyzer
.pytype/
# Cython debug symbols
cython_debug/
.abstra/
.ruff_cache/
.pypirc
marimo/_static/
marimo/_lsp/
__marimo__/
.streamlit/secrets.toml
tempCodeRunnerFile.py

What these Python rules actually ignore

Every pattern below, and why it belongs in your .gitignore.

Byte-compiled / optimized / DLL files

Pattern What it ignores
__pycache__/ Python bytecode cache directory
*.py[codz] Byte-compiled / optimized / DLL files
*$py.class Python/Jython class files

IPython

Pattern What it ignores
profile_default/ IPython default profile
ipython_config.py IPython configuration
.pdm-python 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-build/ IPython
.pixi/* 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/config.toml IPython

C extensions

Pattern What it ignores
*.so Shared object

Distribution / packaging

Pattern What it ignores
.Python Python version marker
build/ Build output directory
develop-eggs/ Python development eggs
dist/ Distribution directory
downloads/ Downloaded files
eggs/ Python egg packages
.eggs/ Python eggs directory
lib/ Library directory
lib64/ 64-bit library directory
parts/ Buildout parts
sdist/ Python source distribution
var/ Distribution / packaging
wheels/ Python wheel packages
share/python-wheels/ Shared Python wheels
*.egg-info/ Python package metadata
.installed.cfg Buildout installed config
*.egg Python egg package
MANIFEST Python manifest file
*.manifest Manifest files
*.spec PyInstaller spec file

Installer logs

Pattern What it ignores
pip-log.txt pip installation log
pip-delete-this-directory.txt pip marker file

Unit test / coverage reports

Pattern What it ignores
htmlcov/ Coverage HTML report
.tox/ tox test environments
.nox/ nox test environments
.coverage Coverage data file
.coverage.* Coverage data files
.cache Cache directory
nosetests.xml Nose test results
coverage.xml Coverage XML report
*.cover Coverage annotated source
*.py.cover Unit test / coverage reports
.hypothesis/ Hypothesis test data
*.lcov LCOV coverage data
.pytest_cache/ pytest cache directory
cover/ Coverage reports

Translations

Pattern What it ignores
*.mo Compiled message catalogs
*.pot Message catalog template

Django stuff:

Pattern What it ignores
*.log Log file
local_settings.py Local Django settings
db.sqlite3 SQLite database
db.sqlite3-journal SQLite journal

Flask stuff:

Pattern What it ignores
instance/ Flask instance folder
.webassets-cache Flask-Assets cache

Scrapy stuff:

Pattern What it ignores
.scrapy Scrapy cache

Sphinx documentation

Pattern What it ignores
docs/_build/ Sphinx build output

PyBuilder

Pattern What it ignores
.pybuilder/ PyBuilder directory
target/ Maven build directory

Jupyter Notebook

Pattern What it ignores
.ipynb_checkpoints Jupyter notebook checkpoints

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

Pattern What it ignores
__pypackages__/ PEP 582 packages

Celery stuff

Pattern What it ignores
celerybeat.pid Celery beat PID file
celerybeat-schedule* Celery stuff

SageMath parsed files

Pattern What it ignores
*.sage.py Sage compiled files

Environments

Pattern What it ignores
.env Environment variables
.envrc Environments
.venv Python virtual environment
env/ Virtual environment directory
venv/ Virtual environment directory
env.bak/ Environment backup
venv.bak/ Virtual env backup

Redis

Pattern What it ignores
*.rdb Redis
*.aof Redis
*.pid Process ID file

RabbitMQ

Pattern What it ignores
mnesia/ RabbitMQ
rabbitmq/ RabbitMQ
rabbitmq-data/ RabbitMQ

ActiveMQ

Pattern What it ignores
activemq-data/ ActiveMQ

Spyder project settings

Pattern What it ignores
.spyderproject Spyder project
.spyproject Spyder project settings

Rope project settings

Pattern What it ignores
.ropeproject Python rope refactoring
/site mkdocs documentation
.mypy_cache/ mypy type checker cache
.dmypy.json mypy daemon config
dmypy.json mypy daemon config

Pyre type checker

Pattern What it ignores
.pyre/ Pyre type checker
.pytype/ pytype static analyzer

Cython debug symbols

Pattern What it ignores
cython_debug/ Cython debug symbols

Learn more at https://abstra.io/docs

Pattern What it ignores
.abstra/ Learn more at https://abstra.io/docs

Ruff stuff:

Pattern What it ignores
.ruff_cache/ Ruff stuff:

PyPI configuration file

Pattern What it ignores
.pypirc PyPI configuration file

Marimo

Pattern What it ignores
marimo/_static/ Marimo
marimo/_lsp/ Marimo
__marimo__/ Marimo

Streamlit

Pattern What it ignores
.streamlit/secrets.toml Streamlit

Temporary file for partial code execution

Pattern What it ignores
tempCodeRunnerFile.py Temporary file for partial code execution

How to use this .gitignore for Python

  1. Copy the Python rules above, or download the file directly.
  2. Create a file named .gitignore at the root of your Git repository and paste the rules into it.
  3. If some of those files are already tracked, run git rm -r --cached . then commit again — Git only applies ignore rules to untracked files.
  4. Commit the .gitignore so everyone on the team shares the same rules.

Other Language .gitignore templates

See every Language template