Skip to main content

Fast Python bindings for the oxc JavaScript/TypeScript parser

Project description

oxc-python

Fast Python bindings for the oxc JavaScript/TypeScript parser.

License: MIT Python 3.10+

What is this?

oxc-python provides Python bindings for oxc's blazing-fast JavaScript and TypeScript parser. oxc is written in Rust and is one of the fastest JS/TS parsers available, outperforming alternatives by 3-5x while maintaining full compatibility with JavaScript and TypeScript standards.

Use cases:

  • Building development tools that analyze JavaScript/TypeScript code
  • Creating AST-based linters or code analyzers
  • Extracting information from JS/TS codebases (imports, exports, functions, etc.)
  • Building code transformation or refactoring tools
  • Any Python application that needs to understand JavaScript/TypeScript syntax

Installation

pip install oxc-python

Note: Package not yet published to PyPI. For now, install from source (see Development section).

Quick Start

import oxc_python

# Parse JavaScript code
result = oxc_python.parse("const x = 42;")
print(result.program.body[0].type)  # VariableDeclaration

# Access the source text of any node
for node, depth in oxc_python.walk(result.program):
    if node.type == "VariableDeclaration":
        print(node.get_text("const x = 42;"))  # const x = 42;

Features

Parser

  • JavaScript (ES2024+) - Full support for modern JavaScript
  • TypeScript - Types, interfaces, enums, decorators
  • JSX/TSX - React syntax support
  • Error Recovery - Get partial AST even with syntax errors
  • Fast - Rust-powered performance
  • Type Stubs - Full type hints for IDE support

API

import oxc_python

# Basic parsing
result = oxc_python.parse("const x = 1;")
# Returns: ParseResult with 'program' and 'errors' fields

# Parse TypeScript
result = oxc_python.parse(
    "const x: number = 1;",
    source_type="module",  # or "script"
)

# Parse JSX/TSX
result = oxc_python.parse(
    "const Component = () => <div>Hello</div>;",
)

# Handle parse errors gracefully
result = oxc_python.parse("const x = ;")  # Syntax error
if result.errors:
    for error in result.errors:
        print(f"Error: {error}")
# Still get partial AST in result.program

# Traverse the AST
for node, depth in oxc_python.walk(result.program):
    indent = "  " * depth
    print(f"{indent}{node.type}")

# Extract source text for any node
source = "const x = 1;\nconst y = 2;"
result = oxc_python.parse(source)
for node, _ in oxc_python.walk(result.program):
    if node.type == "VariableDeclaration":
        text = node.get_text(source)
        line_start, line_end = node.get_line_range(source)
        print(f"Lines {line_start}-{line_end}: {text}")

Examples

Extract All Imports

import oxc_python

source = """
import React from 'react';
import { useState } from 'react';
import * as Utils from './utils';
"""

result = oxc_python.parse(source)

for node, _ in oxc_python.walk(result.program):
    if node.type == "ImportDeclaration":
        module = node.source.value
        print(f"Imports from: {module}")

Find All Function Declarations

import oxc_python

source = """
function foo() {}
async function bar() {}
function* baz() {}
"""

result = oxc_python.parse(source)

for node, _ in oxc_python.walk(result.program):
    if node.type == "FunctionDeclaration":
        name = node.id.name if node.id else "<anonymous>"
        async_flag = "async " if node.async_ else ""
        generator_flag = "* " if node.generator else ""
        print(f"{async_flag}{generator_flag}function {name}")

TypeScript Type Extraction

import oxc_python

source = """
type User = { name: string; age: number };
interface Config { debug: boolean; }
enum Status { Active, Inactive }
"""

result = oxc_python.parse(source)

for node, _ in oxc_python.walk(result.program):
    if node.type == "TSTypeAliasDeclaration":
        print(f"Type alias: {node.id.name}")
    elif node.type == "TSInterfaceDeclaration":
        print(f"Interface: {node.id.name}")
    elif node.type == "TSEnumDeclaration":
        print(f"Enum: {node.id.name}")

Development

This project uses a devcontainer for consistent development environments.

Setup with VS Code (Recommended)

  1. Prerequisites:

  2. Open in devcontainer:

    git clone https://github.com/tylersatre/oxc-python.git
    cd oxc-python
    code .
    
    • When prompted, click "Reopen in Container"
    • Or: Press F1 → "Dev Containers: Reopen in Container"
  3. The devcontainer will automatically:

    • Install all dependencies with uv sync
    • Set up Python virtual environment
    • Configure VS Code with Python, Rust, and Ruff extensions
  4. Build and test:

    # Build the Rust extension
    maturin develop
    
    # Run tests
    pytest
    
    # Run specific test
    pytest tests/test_phase_08_parse_function.py -v
    

Manual Setup (Without Devcontainer)

Requirements:

  • Python 3.10+
  • Rust toolchain (install from rustup.rs)
  • uv (recommended) or pip

Steps:

git clone https://github.com/tylersatre/oxc-python.git
cd oxc-python

# Install dependencies
uv sync  # or: pip install -e ".[dev]"

# Build the extension
maturin develop

# Run tests
pytest

Development Commands

# Build for development
maturin develop

# Build for release (optimized)
maturin develop --release

# Build wheel
maturin build --release

# Format code
ruff format .

# Lint code
ruff check .

# Run tests
pytest

# Run tests with coverage
pytest --cov=oxc_python --cov-report=html

Project Status

Current: v0.1.0 (Pre-release)

This is an early-stage project focused on providing parser bindings only. The API is stable enough for experimentation but may change before v1.0.

What's Included (v0.1)

  • ✅ Full JavaScript/TypeScript/JSX parsing
  • ✅ AST traversal with walk()
  • ✅ Source text extraction with get_text() and get_line_range()
  • ✅ Error recovery
  • ✅ Type stubs for IDE support

Not Yet Included

  • ❌ Linting (oxc linter bindings)
  • ❌ Code transformation/mutation
  • ❌ Formatting (oxc formatter bindings)
  • ❌ Scope analysis
  • ❌ AST modification APIs

These features may be added in future versions based on community interest.

Contributing

Contributions are welcome! This project is in active development for v0.1.0.

How to contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes in the devcontainer
  4. Add tests for new features
  5. Run pytest and ruff check .
  6. Submit a pull request

Areas where we'd love help:

  • Documentation improvements
  • Example scripts
  • Bug reports and fixes
  • Performance benchmarks
  • Feature suggestions

See CLAUDE.md for architectural guidance.

Architecture

oxc-python/
├── src/                    # Rust source code (PyO3 bindings)
│   ├── lib.rs             # Main module
│   ├── parser.rs          # Parser bindings
│   ├── traversal.rs       # walk() implementation
│   └── nodes/             # AST node conversions
├── python/oxc_python/     # Python package
│   ├── __init__.py        # Python API
│   ├── *.pyi              # Type stubs
│   └── py.typed           # PEP 561 marker
├── tests/                 # Python test suite
└── .devcontainer/         # Dev environment config

Performance

oxc is designed for speed. While we haven't published formal benchmarks yet, oxc's Rust parser is typically 3-5x faster than popular JavaScript parsers like Babel or TypeScript's compiler.

The Python bindings add minimal overhead - most time is spent in Rust code.

License

MIT License - see LICENSE file for details.

This project provides Python bindings for oxc, which is also MIT licensed.

Acknowledgments

Built on top of the excellent oxc project by Boshen and contributors. Thank you for creating such a high-quality, fast JavaScript toolchain in Rust!

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oxc_python-0.1.1.tar.gz (118.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

oxc_python-0.1.1-cp310-abi3-win_amd64.whl (634.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

oxc_python-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (727.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

oxc_python-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (708.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

oxc_python-0.1.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (1.4 MB view details)

Uploaded CPython 3.10+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file oxc_python-0.1.1.tar.gz.

File metadata

  • Download URL: oxc_python-0.1.1.tar.gz
  • Upload date:
  • Size: 118.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oxc_python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 66d13a40e6a7ae76d9bb4d014f9cd6653b9f40188948375bb229a475ddbdd6a8
MD5 030ada7a9bb62a20307a95c4617c5209
BLAKE2b-256 15c0e1f1a8f6a07702a62874d6b203973c748013db2b81a3d14870875b076d33

See more details on using hashes here.

Provenance

The following attestation bundles were made for oxc_python-0.1.1.tar.gz:

Publisher: release.yml on tylersatre/oxc-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oxc_python-0.1.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: oxc_python-0.1.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 634.8 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oxc_python-0.1.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cbe58484e8b49b1965cf90421301042bb99d7c24e9522e8b5c09e5e9e98bd7c0
MD5 b8080c278308c7547219c5063e4a4e7c
BLAKE2b-256 4ddba193dd1767aa33574d9c210409d4bd5e89c1310c6a3ac8fd695d25f949df

See more details on using hashes here.

Provenance

The following attestation bundles were made for oxc_python-0.1.1-cp310-abi3-win_amd64.whl:

Publisher: release.yml on tylersatre/oxc-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oxc_python-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for oxc_python-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3c06270545445c3f237d0f8950ed9299c67af3dbe85dea97d599d62e613f2fa6
MD5 8a8dbac8b93708eb8560ea39d19c7be1
BLAKE2b-256 e152075f5606e37e166d8476323bcf35b409033178755ad47dd27e7c28aec5ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for oxc_python-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on tylersatre/oxc-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oxc_python-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for oxc_python-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b34e0604742941d35dee2ca2e6818883274444075807800ab678a59fbb876d54
MD5 fc68a71d30631df35e43ffc51a618b18
BLAKE2b-256 368a011b200e47b7a7c273dcc084e1235762b54f4ebb8c45d0608e9ab876012b

See more details on using hashes here.

Provenance

The following attestation bundles were made for oxc_python-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on tylersatre/oxc-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oxc_python-0.1.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for oxc_python-0.1.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 c43c8de4673b4e70aca89b1beb60d4d2da845d09b7050b0b8e4dafba6ec780ac
MD5 80bbebddf5056cfb2d412631c02fa1bb
BLAKE2b-256 db0a8b3e320a6c216b7748920cb3cea08d8d0c7807d89cdd55783e721e5003d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for oxc_python-0.1.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: release.yml on tylersatre/oxc-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page