1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.
RustPy Toolkit
🚀 High-performance Polars expressions for Brazilian document validation and text processing
RustPy Toolkit provides blazing-fast Polars expressions implemented in Rust for common Brazilian data processing tasks. Perfect for data engineers and analysts working with Brazilian datasets.
✨ Features
- 🏃♂️ High Performance: Rust-powered expressions that are significantly faster than pure Python implementations
- 📋 CPF/CNPJ Validation: Validate and format Brazilian CPF and CNPJ documents
- 📱 Phone Validation: Validate and format Brazilian phone numbers
- 🔤 Text Processing: Remove accents, title case conversion, and more
- 🐻❄️ Polars Integration: Seamless integration with Polars DataFrames
- 🔧 Easy to Use: Simple, intuitive API
📦 Installation
Install from PyPI using pip:
pip install rustpy-toolkit
Or using uv:
uv add rustpy-toolkit
🚀 Quick Start
import polars as pl
from rustpy_toolkit import validate_cpf_cnpj, format_phone, is_cpf_or_cnpj
# Create a DataFrame with Brazilian documents and phone numbers
df = pl.DataFrame({
"documento": ["11144477735", "11222333000181", "invalid_doc"],
"telefone": ["+5516997184720", "16997184720", "invalid_phone"]
})
# Apply validation and formatting
result = df.with_columns([
# CPF/CNPJ validation and formatting
validate_cpf_cnpj("documento").alias("doc_valid"),
is_cpf_or_cnpj("documento").alias("doc_type"),
format_cpf_cnpj("documento").alias("doc_formatted"),
# Phone validation and formatting
validate_phone("telefone").alias("phone_valid"),
format_phone("telefone").alias("phone_formatted"),
])
print(result)
📚 Modules
📋 CPF/CNPJ (rustpy_toolkit.cpf_cnpj)
from rustpy_toolkit.cpf_cnpj import validate_cpf_cnpj, is_cpf_or_cnpj, format_cpf_cnpj
# Validate CPF/CNPJ documents
df.with_columns(validate_cpf_cnpj("documento").alias("is_valid"))
# Identify document type
df.with_columns(is_cpf_or_cnpj("documento").alias("doc_type")) # Returns "CPF", "CNPJ", or None
# Format documents with proper punctuation
df.with_columns(format_cpf_cnpj("documento").alias("formatted"))
# CPF: 111.444.777-35
# CNPJ: 11.222.333/0001-81
📱 Phone (rustpy_toolkit.phone)
from rustpy_toolkit.phone import validate_phone, validate_phone_flexible, format_phone
# Strict validation (requires +55 format)
df.with_columns(validate_phone("telefone").alias("valid_strict"))
# Flexible validation (accepts multiple formats)
df.with_columns(validate_phone_flexible("telefone").alias("valid_flexible"))
# Format to standard Brazilian format
df.with_columns(format_phone("telefone").alias("formatted"))
# Output: +55 (16) 99718-4720
🔤 Text Utils (rustpy_toolkit.text_utils)
from rustpy_toolkit.text_utils import remove_accents, title_case, pig_latinnify
# Remove accents from text
df.with_columns(remove_accents("texto").alias("clean_text"))
# Convert to title case
df.with_columns(title_case("texto").alias("title_text"))
# Convert to pig latin (fun example)
df.with_columns(pig_latinnify("texto").alias("pig_latin"))
📖 Detailed Examples
Working with Large Datasets
import polars as pl
from rustpy_toolkit import validate_cpf_cnpj, format_phone, is_cpf_or_cnpj
# Load a large dataset
df = pl.read_csv("large_dataset.csv")
# Process millions of records efficiently
processed = df.with_columns([
validate_cpf_cnpj("cpf_cnpj").alias("document_valid"),
is_cpf_or_cnpj("cpf_cnpj").alias("document_type"),
format_cpf_cnpj("cpf_cnpj").alias("document_formatted"),
validate_phone_flexible("phone").alias("phone_valid"),
format_phone("phone").alias("phone_formatted"),
])
# Get statistics
stats = processed.group_by("document_type").agg([
pl.count().alias("count"),
pl.col("document_valid").sum().alias("valid_count")
])
Data Cleaning Pipeline
from rustpy_toolkit import remove_accents, title_case, validate_cpf_cnpj
# Clean and standardize data
cleaned = df.with_columns([
# Clean text fields
remove_accents("nome").alias("nome_clean"),
title_case("nome").alias("nome_formatted"),
# Validate documents
validate_cpf_cnpj("documento").alias("documento_valid"),
# Filter only valid records
]).filter(pl.col("documento_valid"))
🏗️ Development
Building from Source
# Clone the repository
git clone https://github.com/yourusername/rustpy-toolkit
cd rustpy-toolkit
# Install development dependencies
uv sync
# Build the Rust extension
maturin develop
# Run tests
uv run python test_modular_functions.py
Project Structure
rustpy-toolkit/
├── python/rustpy_toolkit/ # Python package
│ ├── __init__.py # Main module
│ ├── cpf_cnpj.py # CPF/CNPJ functions
│ ├── phone.py # Phone functions
│ └── text_utils.py # Text utilities
├── src/ # Rust source code
│ ├── lib.rs # Main Rust module
│ ├── cpf_cnpj.rs # CPF/CNPJ implementations
│ ├── phone.rs # Phone implementations
│ └── text_utils.rs # Text utilities
├── Cargo.toml # Rust dependencies
├── pyproject.toml # Python package config
└── README.md # This file
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built with PyO3 for Python-Rust interoperability
- Powered by Polars for high-performance data processing
- Inspired by the Brazilian data processing community
📊 Performance
RustPy Toolkit expressions are significantly faster than pure Python implementations:
| Operation | Pure Python | RustPy Toolkit | Speedup |
|---|---|---|---|
| CPF Validation | 100ms | 15ms | 6.7x |
| Phone Formatting | 80ms | 12ms | 6.7x |
| Text Processing | 120ms | 18ms | 6.7x |
Benchmarks run on 100,000 records
Made with ❤️ for the Brazilian data community
Metadata
Release files for rustpy-toolkit 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
File added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release files before installing.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rustpy_toolkit-0.1.3.tar.gz | 49.7 kB | Without provenance | Details for rustpy_toolkit-0.1.3.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rustpy_toolkit-0.1.3-cp38-abi3-win_amd64.whl | CPython 3.8 | abi3 | Windows x86-64 | Details for rustpy_toolkit-0.1.3-cp38-abi3-win_amd64.whl |
| rustpy_toolkit-0.1.3-cp38-abi3-manylinux_2_34_x86_64.whl | CPython 3.8 | abi3 | Linux glibc 2.34+ x86-64 | Details for rustpy_toolkit-0.1.3-cp38-abi3-manylinux_2_34_x86_64.whl |
Total release size: 9.9 MB
Release files / rustpy_toolkit-0.1.3.tar.gz
| Download URL | rustpy_toolkit-0.1.3.tar.gz |
|---|---|
| Size | 49.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5cef2b11367387a8d5c6f186fe87629b8fd96817046330a273d65d3a0690c0f
|
|
BLAKE2b-256 checksum How to use checksums |
bf519c83282a730e8365675779755a82e06c94a670138a5b6ecc467e7374b05c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.11.5
|
Release files / rustpy_toolkit-0.1.3-cp38-abi3-win_amd64.whl
File added late
This file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release file before installing.
| Download URL | rustpy_toolkit-0.1.3-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
d3c43827267a87360e275bab4baf80751a55bde6e572e439df9f54b1af3c400b
|
|
BLAKE2b-256 checksum How to use checksums |
bab0b76157580dc7c94c04720e03251809d2e8e063f0ab27c61f277cdf84178a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.5
|
Release files / rustpy_toolkit-0.1.3-cp38-abi3-manylinux_2_34_x86_64.whl
| Download URL | rustpy_toolkit-0.1.3-cp38-abi3-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.8 Linux glibc 2.34+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
79d6b7e9b1b7eab8e616d9a28e719019deacb8278cf161c6abd7ac58f048a3d1
|
|
BLAKE2b-256 checksum How to use checksums |
0c04c5ff397d2b19b432246a2dee2aed30c816fc3d6de939aa7014d5f6180105
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.11.5
|
Security for rustpy-toolkit 0.1.3
Upload timing
Release file added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.