@codemirror/lang-python
Python language support for the CodeMirror code editor, with highlighting, indentation, and autocompletion.
Repository Health
Technical Analysis
@codemirror/lang-python adds first-class Python editing to CodeMirror 6. It wraps the Lezer Python parser in a CodeMirror LanguageSupport, layering on syntax highlighting, context-aware indentation for blocks and continuation lines, code folding, and completion sources for both built-in globals and locally defined names.
Dropping the python() extension into an EditorView gives you a Python-aware editing surface without hand-rolling tokenizers or indentation heuristics. It is one of the official CodeMirror language packages, sharing the same architecture and release conventions as the rest of the ecosystem.
What You Get
- A ready-to-use
python()LanguageSupport extension for CodeMirror 6. - Syntax highlighting driven by the Lezer Python grammar.
- Context-aware indentation for blocks, brackets, and continuation lines, including match/case, else/elif, and except handling.
- Autocompletion for Python built-in globals, keywords, and locally defined names.
- Code folding for functions, classes, collections, and multiline strings.
Common Use Cases
- Building an in-browser Python code editor or REPL front-end.
- Adding a Python editing mode to a documentation site, notebook, or teaching tool.
- Powering code cells in a low-code or data-science web application.
Under The Hood
Architecture — The package is a thin, well-factored integration layer over the Lezer Python parser. src/python.ts defines pythonLanguage as an LRLanguage that configures the imported Lezer parser with indentNodeProp and foldNodeProp metadata; helper functions innerBody and indentBody walk the syntax tree to resolve Python’s whitespace-significant indentation, handling block bodies, match/case, and deindenting keywords. The exported python() factory returns a LanguageSupport bundling the language with two autocomplete data providers wired from src/complete.ts.
Tech Stack — Written entirely in TypeScript (100% of the source), it depends on @lezer/python and @lezer/common for parsing plus @codemirror/language, @codemirror/autocomplete, and @codemirror/state for editor integration. It builds to dual ESM/CJS output via the @codemirror/buildhelper toolchain (cm-buildhelper), ships type definitions, and is marked sideEffects: false for tree-shaking.
Code Quality — The codebase is compact (~12KB of source across python.ts and complete.ts) and idiomatic for the CodeMirror ecosystem, using a NodeWeakMap cache and a declarative gatherCompletions table keyed by node type to collect scoped definitions. Public APIs carry doc comments. Testing is present via a test-indent.ts suite run with cm-runtests, focused on the indentation logic that is the trickiest part of the package.
API Design — The public surface is minimal and ergonomic: importing python() and adding it to an editor’s extensions is the entire happy path, matching the uniform convention shared across all official CodeMirror language packages. Lower-level exports (pythonLanguage, globalCompletion, localCompletionSource) let advanced users compose custom behavior. The README documents each export with linked type references, keeping boilerplate near zero.
Used by 26 apps in this directory
MaxKB
AI Development · Knowledge Management
Build enterprise-grade AI agents with RAG, workflows & multi-modal support
Metabase
Analytics
The open-source BI platform that lets anyone ask questions and build dashboards without writing SQL — with an embedded analytics SDK and AI-powered query assistant included.
n8n
Automation · No Code Platforms
Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.
NocoBase
Low Code Platforms · No Code Platforms
Open-source AI + no-code platform that lets coding agents and people collaborate to build business systems fast on proven infrastructure.
OpenKnowledge
Code Editors · Knowledge Management · Note Taking
A beautiful, local-first markdown IDE that turns any git repo into a live collaborative workspace for humans and AI coding agents like Claude, Codex, and OpenCode.
Open WebUI
AI Agents · AI Assistants
The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.
OpenViking
AI Development · AI Memory · Databases
An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.
overleaf
Collaboration · Productivity
Open-source, real-time collaborative LaTeX editor with sandboxed compilation and full TeXLive support for self-hosted academic and research teams.
Arize Phoenix
Analytics · Devops · Monitoring
Open-source AI observability platform for tracing, evaluating, and debugging LLM applications with built-in intelligence and MCP support.