or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/pypi-basedpyright

Static type checking for Python with enhanced features and improvements over pyright

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/basedpyright@1.31.x

To install, run

npx @tessl/cli install tessl/pypi-basedpyright@1.31.0

index.mddocs/

Basedpyright

Basedpyright 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.

Package Information

  • Package Name: basedpyright
  • Language: Python
  • Installation: pip install basedpyright or uv add basedpyright

Core Imports

from basedpyright.pyright import main as pyright_main
from basedpyright.langserver import main as langserver_main
from basedpyright.run_node import run

Basic Usage

Command Line Type Checking

# 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

Language Server Mode

# Start language server for IDE integration
basedpyright-langserver --stdio

Programmatic Usage (Python API)

from 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' command

Capabilities

CLI Type Checking

Primary 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.
    """

Language Server Protocol

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.
    """

Node.js Execution Helper

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.
    """

Configuration

Project Configuration

Basedpyright can be configured through multiple methods:

pyproject.toml (recommended):

[tool.basedpyright]
pythonVersion = "3.11"
include = ["src"]
exclude = ["tests"]
reportMissingImports = true

pyrightconfig.json:

{
  "pythonVersion": "3.11",
  "include": ["src"],
  "exclude": ["tests"],
  "reportMissingImports": true
}

Supported Python Versions

  • Python 3.8, 3.9, 3.10, 3.11, 3.12, 3.13

Runtime Requirements

  • nodejs-wheel-binaries>=20.13.1: Provides Node.js runtime for executing the type checker

CLI Commands

basedpyright

# 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

basedpyright-langserver

# Entry point: basedpyright.langserver:main  
# Description: Language server protocol implementation
# Usage:

basedpyright-langserver --stdio
basedpyright-langserver --socket=5007

Error Handling

The CLI commands exit with standard exit codes:

  • 0: No errors found
  • 1: Type errors or other issues found
  • 2: Fatal error or invalid configuration

Language server mode runs continuously until terminated by the client.

Integration Notes

  • IDE Integration: Use basedpyright-langserver for VS Code, PyCharm, Vim, Emacs, and other LSP-compatible editors
  • CI/CD: Use basedpyright in build scripts and pre-commit hooks
  • API Limitations: No programmatic Python API for accessing type checking results - all functionality accessed through CLI or language server protocol