Static type checking for Python with enhanced features and improvements over pyright
npx @tessl/cli install tessl/pypi-basedpyright@1.31.0Basedpyright is a static type checker for Python, built as a fork of Microsoft's pyright with enhanced type checking capabilities, additional pylance features, and various improvements. It provides comprehensive static analysis, intelligent error detection, and language server protocol support for Python development environments.
pip install basedpyright or uv add basedpyrightfrom basedpyright.pyright import main as pyright_main
from basedpyright.langserver import main as langserver_main
from basedpyright.run_node import run# Check a single file
basedpyright myfile.py
# Check a project directory
basedpyright src/
# Check with specific configuration
basedpyright --project pyproject.toml
# Show version information
basedpyright --version# Start language server for IDE integration
basedpyright-langserver --stdiofrom basedpyright.pyright import main as pyright_main
from basedpyright.langserver import main as langserver_main
# Execute type checking programmatically (exits process)
pyright_main() # Equivalent to running 'basedpyright' command
# Start language server programmatically (exits process)
langserver_main() # Equivalent to running 'basedpyright-langserver' commandPrimary interface for static type analysis of Python code. Supports project-wide checking, incremental analysis, and comprehensive error reporting.
def main():
"""
Main entry point for basedpyright CLI type checker.
Executes the Node.js basedpyright implementation with command line arguments.
Supports all pyright CLI options and basedpyright-specific enhancements.
Exits the process with the type checker's exit code.
"""Provides IDE integration through Language Server Protocol, enabling real-time type checking, autocompletion, hover information, and other language features.
def main():
"""
Entry point for basedpyright language server.
Starts the language server for IDE integration via Language Server Protocol.
Communicates through stdin/stdout for editor integration.
Exits the process when language server terminates.
"""Internal utility for executing the underlying Node.js type checker implementation.
def run(script_name: str):
"""
Execute a Node.js script from the basedpyright package.
Args:
script_name (str): Name of the JavaScript file to execute (without .js extension).
Valid values:
- "index" - executes the main CLI type checker
- "langserver.index" - executes the language server
The function looks for {script_name}.js in the basedpyright package directory
and executes it with Node.js, passing through all command line arguments.
Exits the process with the Node.js script's exit code.
"""Basedpyright can be configured through multiple methods:
pyproject.toml (recommended):
[tool.basedpyright]
pythonVersion = "3.11"
include = ["src"]
exclude = ["tests"]
reportMissingImports = truepyrightconfig.json:
{
"pythonVersion": "3.11",
"include": ["src"],
"exclude": ["tests"],
"reportMissingImports": true
}# Entry point: basedpyright.pyright:main
# Description: Main type checker CLI command
# Common usage patterns:
# Basic type checking
basedpyright .
basedpyright src/ tests/
# With configuration
basedpyright --project pyproject.toml
basedpyright --pythonversion 3.11
# Output formats
basedpyright --outputjson
basedpyright --stats
# Watch mode
basedpyright --watch# Entry point: basedpyright.langserver:main
# Description: Language server protocol implementation
# Usage:
basedpyright-langserver --stdio
basedpyright-langserver --socket=5007The CLI commands exit with standard exit codes:
Language server mode runs continuously until terminated by the client.
basedpyright-langserver for VS Code, PyCharm, Vim, Emacs, and other LSP-compatible editorsbasedpyright in build scripts and pre-commit hooks