Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python bindings #393

Closed
wants to merge 19 commits into from
Closed

Python bindings #393

wants to merge 19 commits into from

Conversation

dirvine
Copy link
Member

@dirvine dirvine commented Oct 30, 2024

Python Bindings for self_encryption

This PR adds comprehensive Python bindings to the self_encryption library using PyO3, making the library's functionality accessible to Python developers.

Features Added

1. Core Python Bindings

  • Basic encryption/decryption operations
  • File-based operations with chunk storage
  • Streaming interface for large files
  • Full type safety and error handling
  • Proper memory management between Rust and Python

2. Python Package Infrastructure

  • Added pyproject.toml for modern Python packaging
  • Configured maturin for Rust/Python interop
  • Set up cross-platform wheel building
  • Added Python-specific documentation

3. CI/CD Pipeline

  • Added GitHub Actions workflow for Python package publishing
  • Configured PyPI trusted publisher setup
  • Cross-platform wheel building (Linux, macOS, Windows)
  • Multiple Python version support (3.8-3.12)

Example Usage

# Basic encryption/decryption
from self_encryption import encrypt_bytes, decrypt_chunks

data = b"Hello World" * 1024
data_map, chunks = encrypt_bytes(data)
decrypted = decrypt_chunks(data_map, chunks)

# File-based operations
from self_encryption import encrypt_file, decrypt_from_files

data_map, chunk_files = encrypt_file("input.txt", "chunks_dir")
decrypt_from_files("chunks_dir", data_map, "output.txt")

# Streaming interface
from self_encryption import StreamSelfEncryptor, StreamSelfDecryptor

encryptor = StreamSelfEncryptor("input_file.dat", chunk_dir="chunks_dir")
# ... process chunks ...

Testing

  • Added Python examples in README
  • Verified cross-platform compatibility
  • Tested with various Python versions
  • Memory safety checks
  • Error handling verification

Documentation

  • Updated README with Python usage examples
  • Added inline documentation for Python functions
  • Included type hints and docstrings

Future Work

  • Add more Python-specific examples
  • Consider adding async support
  • Add Python-specific optimizations
  • Consider adding more Pythonic interfaces

Breaking Changes

None - This is a new feature that doesn't affect existing Rust functionality.

Dependencies Added

  • maturin (build system)
  • PyO3 (Rust/Python bindings)

Testing Instructions

  1. Install the package:
pip install self-encryption
  1. Run the examples from the README to verify functionality

Notes

  • Minimum supported Python version is 3.8
  • Requires rustc 1.65 or higher
  • Cross-platform support for Windows, macOS, and Linux

@dirvine dirvine requested a review from a team as a code owner October 30, 2024 22:45
* Reorganize README.md to clearly document both Rust and Python interfaces
* Add Python installation and usage examples
* Configure pyproject.toml to use Cargo.toml version via maturin
* Maintain all existing Rust documentation and imagery
* Keep security notes and whitepaper references prominent

The Python package will automatically sync its version with Cargo.toml
using maturin's dynamic versioning feature.
@dirvine dirvine closed this Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant