Skip to main content

spicycrab

A Python to Rust transpiler for type-annotated Python code.

Note: spicycrab and cookcrab are under active development. APIs, CLI options, and generated code may change frequently.

Features

  • crabpy - Transpile Python code to Rust
  • cookcrab - Generate Python stubs from Rust crates

Installation

python3 -m pip install spicycrab

Development Setup

# Clone the repository
git clone https://github.com/kushaldas/spicycrab.git
cd spicycrab

# Create virtual environment
uv venv
source .venv/bin/activate

# Install with all development and documentation dependencies
uv pip install -e ".[dev,docs]"

# Verify installation
crabpy --version
cookcrab --version

Quick Start

Transpile Python to Rust

crabpy transpile input.py -o rust_output -n my_project
crabpy transpile src/ -o rust_project/ -n my_project

Use Rust Crates in Python

# Generate stubs for a Rust crate
cookcrab generate clap -o /tmp/stubs

# Install the generated stubs
python3 -m pip install -e /tmp/stubs/clap_builder
python3 -m pip install -e /tmp/stubs/clap

# Write Python code using Rust crate types
cat > myapp.py << 'EOF'
from spicycrab_clap import Command, Arg, ArgMatches

def main() -> None:
    matches: ArgMatches = (
        Command.new("myapp")
        .arg(Arg.new("name").required(True))
        .get_matches()
    )
    name: str = matches.get_one("name").unwrap().clone()
    print(f"Hello, {name}!")
EOF

# Transpile to Rust
crabpy transpile myapp.py -o rust_myapp -n myapp

# Build and run
cd rust_myapp && cargo build --release
./target/release/myapp World

Requirements

  • Python 3.10+
  • All Python code must have type annotations

Supported Python Features

String Methods

The transpiler supports common Python string methods with automatic Rust equivalents:

Python Rust
s.upper() s.to_uppercase()
s.lower() s.to_lowercase()
s.strip() s.trim().to_string()
s.replace(a, b) s.replace(a, b)
s.startswith(x) s.starts_with(x)
s.endswith(x) s.ends_with(x)
s.split(sep) s.split(sep).collect::<Vec<_>>()
s.join(iter) iter.join(&s)
s.isdigit() s.chars().all(|c| c.is_ascii_digit())
s.find(x) >= 0 s.contains(x)
s.find(x) == -1 !s.contains(x)

Index Operations

Integer variables used for indexing are automatically cast to usize:

# Python
values: list[int] = [1, 2, 3]
i: int = 0
while i < len(values):
    print(values[i])
    i = i + 1
// Generated Rust
let values: Vec<i64> = vec![1, 2, 3];
let mut i: i64 = 0;
while (i as usize) < values.len() {
    println!("{}", values[i as usize]);
    i += 1;
}

Membership Operators

The in and not in operators are supported:

if x in container:      # -> container.contains(&x)
if x not in container:  # -> !container.contains(&x)

Error Handling

Functions returning Result[T, E] automatically get ? operator propagation:

def might_fail() -> Result[int, str]:
    return Ok(42)

def caller() -> Result[int, str]:
    value: int = might_fail()  # Automatically gets ? operator
    return Ok(value + 1)

Release files for spicycrab 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spicycrab 0.1.1
File Size Uploaded
spicycrab-0.1.1.tar.gz 235.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for spicycrab 0.1.1
File
spicycrab-0.1.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
spicycrab-0.1.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details
spicycrab-0.1.1-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
spicycrab-0.1.1-cp314-cp314-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.12+ x86-64 Details

Total release size: 5.7 MB

Release files / spicycrab-0.1.1.tar.gz

Download URL spicycrab-0.1.1.tar.gz
Size 235.9 kB
Tags Source
SHA-256 checksum
How to use checksums
99e36fa41cdc029d0e15f4fa0c674ac9319ca6ec57715af303ef8ebccfc991f7
BLAKE2b-256 checksum
How to use checksums
5dd056824474308fd5dcb50f09cd52b5cc9adf5fb5c383a37bb53540e607eedb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.

Transparency log

Release files / spicycrab-0.1.1-cp314-cp314-win_amd64.whl

Download URL spicycrab-0.1.1-cp314-cp314-win_amd64.whl
Size 1.3 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
0947ef3af5300075e747ebd8cb211ba7f3ad7a39e59f801ea83b5cbf2777213c
BLAKE2b-256 checksum
How to use checksums
d4597477cbe4b8e7382fdc9f92c4ce32cc75867d83e68865428b9bca01077715
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.

Transparency log

Release files / spicycrab-0.1.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL spicycrab-0.1.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.4 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
653bfbbd4b23db955ad9b40ffceda188542aae501333138f61b189fd39cdcf41
BLAKE2b-256 checksum
How to use checksums
d7e9950a4a23edaa063e3148aafaffa0ae4912ad85fa4950e3a2e35859f03df4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.

Transparency log

Release files / spicycrab-0.1.1-cp314-cp314-macosx_11_0_arm64.whl

Download URL spicycrab-0.1.1-cp314-cp314-macosx_11_0_arm64.whl
Size 1.3 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b199f5d32236fd4d14f04abb4ef06b6d431ed5840d41642bb42f15186144821f
BLAKE2b-256 checksum
How to use checksums
8f61ccd6daa93f2f769c11abc1a16cbcaadeac2dd9b6889fec011bf9ecde2e54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.

Transparency log

Release files / spicycrab-0.1.1-cp314-cp314-macosx_10_12_x86_64.whl

Download URL spicycrab-0.1.1-cp314-cp314-macosx_10_12_x86_64.whl
Size 1.4 MB
Tags CPython 3.14 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
6535c0ceb831a810ac105a473cd25f889aae5ef658c309706c68e50c2d42a830
BLAKE2b-256 checksum
How to use checksums
e353f53483051d263c3155ec80146e5d5b45759475f7d945491bcbadd6c4216c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

5 release files

0.0.1

5 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page