Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 89 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,90 @@
# Rewriting a Python Script in Rust

### PURPOSE

The purpose of this project is to rewrite an existing Python script used for data processing in the Rust programming language. The main goals of this project are as follows:
1. Code Migration: Rewrite the Python script in Rust, ensuring it performs the same data processing tasks.
2. Performance Enhancement: Evaluate the improvements in terms of execution speed and resource usage after the migration to Rust.

***

### PROCESS

To achieve the objectives of this project, the following steps are taken:
1. Script Selection: Selected an existing Python script for data processing. This script served as a suitable candidate for migration to Rust.
2. Rewrite in Rust: Rewrote the selected Python script in Rust while maintaining the same functionality. This step involved translating the Python code into idiomatic Rust code.
3. Testing and Debugging: Tested the Rust script to ensure it produces the expected results. Debugged and fixed any issues that arose during the migration.
4. Benchmarking: Conducted performance benchmarking tests to evaluate the improvements in execution speed and resource usage achieved by the Rust version of the script.
5. Documentation: Documented the entire process, including the code migration and performance benchmarking. Created a performance comparison report in Markdown format (README).

***

### Commands to Run the Repo

To run the project, you can use the Makefile and follow these commands:
1. ```
# To install the required the python packages
make install
```
2. ```
# To check code style
make lint
```
3. ```
# To run tests
make test
```
4. ```
# To format the code
make format
```
5. ```
# To extract data
make extract
```
6. ```
# To tranform data
make transform_load
```
7. ```
# To query data
make query
```
# Rewriting a Python Script in Rust | Python to Rust Migration Example

**Migrate Python data-processing code to Rust for better performance.** This repository demonstrates a full Python-to-Rust rewrite: same logic (factorial), testing, linting, and benchmarking—useful for learning Rust migration and comparing Python vs Rust speed.

---

## What This Project Does

This project **rewrites an existing Python script in Rust** and compares performance. It is a practical example of:

- **Code migration** — Translating a Python data-processing script into idiomatic Rust while keeping behavior identical.
- **Performance comparison** — Measuring execution speed and resource usage of the Rust version vs the Python version.

Use this repo to learn **how to rewrite Python in Rust**, see **Rust vs Python performance** on a small workload, and follow a **Python to Rust migration** workflow with tests and tooling.

---

## Quick Start

**Prerequisites:** [Rust](https://www.rust-lang.org/tools/install) (and optionally Python 3 for the original script).

```bash
# Format, lint, test, and run the Rust program
make format
make lint
make test
make run
```

**Run the Python version:**

```bash
make python_install # install Python deps
make python_test # run tests
make python_format # format with Black
make python_lint # lint with Ruff
```

---

## Project Structure

| Path | Purpose |
|------|--------|
| `main.py`, `mylib/` | Original Python script and library |
| `src/main.rs`, `src/lib.rs` | Rust equivalent (factorial logic) |
| `Makefile` | Commands for Rust and Python (format, lint, test, run) |
| `Cargo.toml` | Rust project and dependencies |

---

## How the Migration Was Done

1. **Script selection** — A small Python script (factorial/data-style processing) was chosen as the migration target.
2. **Rewrite in Rust** — The script was reimplemented in Rust with the same behavior.
3. **Testing and debugging** — Tests and manual checks ensure Rust output matches Python.
4. **Benchmarking** — Execution time and resource usage are compared between Python and Rust.
5. **Documentation** — Process and results are documented (including this README).

---

## Makefile Commands

| Command | Description |
|--------|-------------|
| `make format` | Format Rust code (`cargo fmt`) |
| `make lint` | Lint Rust code (Clippy) |
| `make test` | Run Rust tests |
| `make run` | Run the Rust binary |
| `make release` | Build release binary |
| `make python_install` | Install Python dependencies |
| `make python_test` | Run Python tests (pytest) |
| `make python_format` | Format Python with Black |
| `make python_lint` | Lint Python with Ruff |

---

## Author & Contact

**KuchikiRenji**

- **Email:** [KuchikiRenji@outlook.com](mailto:KuchikiRenji@outlook.com)
- **GitHub:** [github.com/KuchikiRenji](https://github.com/KuchikiRenji)
- **Discord:** `kuchiki_renji`

---

## License

See [LICENSE](LICENSE) in this repository.
Loading