Python-to-JavaScript transpiler that enables Python 3 development in web browsers with full DOM integration and standard library support
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Command-line interface for managing Brython projects, installing packages, creating distributions, and running development servers. The CLI provides essential tools for Python developers to work with Brython projects efficiently.
Install Brython runtime files into a new or existing directory, setting up the basic structure for Brython development.
def install(install_dir: str = ".", no_demo: bool = False) -> None:
"""
Install Brython files to directory.
Args:
install_dir: Target directory for installation (default: current directory)
no_demo: Skip installation of demo.html file
Creates:
- brython.js: Core Brython runtime
- brython_stdlib.js: Standard library bundle
- index.html: Basic HTML template
- demo.html: Example usage (unless no_demo=True)
"""Usage:
brython-cli install
brython-cli install --install-dir /path/to/project
brython-cli install --no-demoUpdate existing Brython installations with the latest runtime files while preserving custom project files.
def update(update_dir: str = ".") -> None:
"""
Update Brython scripts in existing project.
Args:
update_dir: Directory containing Brython project to update
Updates:
- brython.js: Core runtime to latest version
- brython_stdlib.js: Standard library to latest version
"""Usage:
brython-cli update
brython-cli update --update-dir /path/to/projectAdd Python packages from the current environment to Brython projects for browser usage.
def add_package(package: str, dest_dir: str = None) -> None:
"""
Add Python package to Brython project.
Args:
package: Name of installed Python package to add
dest_dir: Destination directory (default: ./Lib/site-packages)
Copies package files from current Python environment to Brython project,
making them available for import in browser Python scripts.
"""Usage:
brython-cli add_package requests
brython-cli add_package django --dest-dir custom/libCreate optimized browser-loadable packages from Python source code.
def make_package(package_name: str, src_dir: str = ".", exclude_dirs: list[str] = None, output_path: str = None) -> None:
"""
Create browser-loadable .brython.js package file.
Args:
package_name: Name for the package (used in imports)
src_dir: Source directory containing Python files
exclude_dirs: Directories to exclude from package
output_path: Output path for .brython.js file
Creates optimized JavaScript file containing Python package
that can be loaded in browsers.
"""Usage:
brython-cli make_package mylib
brython-cli make_package mylib --src-dir src/ --exclude-dirs tests docs
brython-cli make_package mylib -o dist/mylib.brython.jsCreate optimized module bundles containing only the modules used by the application.
def make_modules(output_path: str = None, reset: bool = False, modules_paths: str = None) -> None:
"""
Create brython_modules.js with application modules.
Args:
output_path: Output path for modules file
reset: Reset to standard library only
modules_paths: File containing module paths to include
Analyzes application code and creates optimized bundle
containing only required modules.
"""Usage:
brython-cli make_modules
brython-cli make_modules --reset
brython-cli make_modules -o custom_modules.jsCreate Python distributions for PyPI upload from web applications.
def make_dist() -> None:
"""
Create Python distribution for PyPI upload.
Analyzes current project and creates setup.py and distribution
files suitable for uploading to PyPI.
"""Usage:
brython-cli make_distCreate JavaScript virtual file systems from directory structures.
def make_file_system(vfs_name: str, prefix: str = None) -> None:
"""
Create JavaScript file system from directory.
Args:
vfs_name: Name for the virtual file system
prefix: Prefix for file paths in VFS
Creates JavaScript file containing directory structure
that can be loaded as virtual file system in browsers.
"""Usage:
brython-cli make_file_system assets
brython-cli make_file_system templates /templatesStart lightweight development server for testing Brython applications locally.
def start_server(port: int = 8000, bind: str = "localhost") -> None:
"""
Start development server.
Args:
port: Port number to listen on
bind: Address to bind to
Starts HTTP server serving static files from current directory
with proper MIME types for Brython development.
"""Usage:
brython-cli start_server
brython-cli start_server 3000
brython-cli start_server 8080 --bind 0.0.0.0Display version information for the installed Brython CLI.
def version() -> str:
"""
Get Brython version information.
Returns:
Version string for current Brython installation
"""Usage:
brython-cli --versionAll commands are accessed through the brython-cli console script:
brython-cli <command> [options]Available Commands:
install (alias: init) - Install Brython to directoryupdate - Update Brython filesadd_package - Add Python packagemake_package - Create loadable packagemake_modules - Bundle application modulesmake_dist - Create PyPI distributionmake_file_system - Create virtual file systemstart_server - Start development server--version - Show versionGlobal Options:
--help - Show help information--help available for detailed optionsTypical development setup workflow:
# Create new project directory
mkdir my-web-app
cd my-web-app
# Install Brython files
brython-cli install
# Add required packages
brython-cli add_package requests
brython-cli add_package beautifulsoup4
# Start development server
brython-cli start_server 8000This creates a ready-to-use Brython development environment with all necessary files and dependencies.
Install with Tessl CLI
npx tessl i tessl/pypi-brython