py
What is a .py file?
text/x-python
Python (.py) is a plain-text source file for the Python programming language — a dynamically typed, indentation-structured language widely used for scripting, data science, web back-ends, and automation. A .py file is compiled to bytecode and run by the Python interpreter.
How to use a .py file
Use an example .py file to test syntax highlighters, linters (like flake8 or ruff), formatters (black), tree-sitter grammars, and language-detection or code-editor tooling against known-correct source.
Download example .py files
- Python — Hello WorldThe classic hello-world in idiomatic Python 3, with a shebang, a module docstring, and the standard main guard — the minimal correct program for testing highlighters and interpreters.
- Python — Fibonacci (dataclass, generator, type hints)A realistic Python snippet exercising type hints, an lru_cache-memoised recursive function, a generator, and a frozen dataclass — for testing syntax highlighters, linters (ruff/flake8), and formatters (black).
- Python — Intentionally Invalid IndentIntentionally invalid Python indentation for linter / parser error-path tests. Labelled intentionally invalid in title and description.
- Python Dataclass SAMPLEPython dataclass SAMPLE for highlighter and type-checker smoke tests.
- Python Async GatherTiny asyncio gather stub for async Python tooling.
- Python — Intentionally Invalid MatchIntentionally invalid Python match (missing colon) for linters.
- Python Lint Invalid — Unused Import InvalidIntentionally lint-bait SAMPLE python snippet (unused-import-invalid) for rule-engine tests.
- Python Lint Invalid — Bare Except InvalidIntentionally lint-bait SAMPLE python snippet (bare-except-invalid) for rule-engine tests.
and 2 more in the library.