Skip to main content

A library to accelerate Python execution through binary compilation

Project description

PySpeedBoost

PySpeedBoost is a Python library designed to significantly improve Python execution speed by automatically generating and using optimized binary counterparts of Python scripts using Nuitka.

Features

  • Automatic compilation of Python scripts to optimized binaries
  • Seamless integration with existing code via decorators
  • Intelligent caching system to avoid recompilation of unchanged scripts
  • Command-line interface for easy use
  • Cross-platform support (tested on Linux)

Installation

Prerequisites

  • Python 3.7+
  • C++ compiler (g++ or clang)
  • patchelf (required on Linux systems)

System Dependencies

On Ubuntu/Debian systems:

sudo apt-get update
sudo apt-get install python3-dev g++ patchelf

On CentOS/RHEL systems:

sudo yum install python3-devel gcc-c++ patchelf

Install PySpeedBoost

pip install pyspeedboost

Or install from source:

git clone https://github.com/Chrispin-m/pyspeedboost.git
cd pyspeedboost
pip install -e .

Usage

Basic Usage with Decorator

# app.py
from pyspeedboost import speedboost

@speedboost
def main():
    # Your computationally intensive code here
    result = 0
    for i in range(1000000):
        result += i
    print(f"Result: {result}")

if __name__ == "__main__":
    main()

Run your script normally:

python app.py

On the first run, PySpeedBoost will compile your script to a binary. Subsequent runs will use the compiled binary for faster execution.

Advanced Configuration

from pyspeedboost import PySpeedBoost, CompilerConfig

# Create a custom configuration
config = CompilerConfig(
    output_dir="binaries",
    optimization_level=2,
    enable_lto=True,
    quiet_mode=False
)

# Create compiler instance
compiler = PySpeedBoost(config)

# Compile a specific script
compiler.compile("my_script.py")

# Force recompilation
compiler.compile("my_script.py", force=True)

Command Line Interface

# Compile a script
pyspeedboost compile my_script.py

# Run a script with binary acceleration
pyspeedboost run my_script.py

# Clean compiled binaries
pyspeedboost clean

# Show version information
pyspeedboost version

Performance

PySpeedBoost can significantly improve execution speed for CPU-intensive applications. However, the performance gain varies depending on the nature of your code:

  • Best for computationally intensive applications
  • Less beneficial for I/O-bound applications
  • First run includes compilation time, so it may be slower

Example Performance Results

Running with standard Python...
Running compiled version...
Interpreted time: 0.6244 seconds
Compiled time: 0.6573 seconds
Speedup: 0.95x

Note: In this specific test, the compiled version was slightly slower(first run on top), but performance gains are typically more significant for more complex computations.

Testing

To verify your installation, run the test suite:

# Run unit tests
python -m pytest tests/test_pyspeedboost.py -v

# Run performance test
python tests/performance_test.py

Expected test output:

============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-8.4.2, pluggy-1.6.0 -- /dirs/pyspeedboost/venv/bin/python
cachedir: .pytest_cache
rootdir: /dirs/pyspeedboost
collected 4 items                                                              

tests/test_pyspeedboost.py::test_compiler_initialization PASSED          [ 25%]
tests/test_pyspeedboost.py::test_binary_path_generation PASSED           [ 50%]
tests/test_pyspeedboost.py::test_compile_and_run_simple_script PASSED    [ 75%]
tests/test_pyspeedboost.py::test_decorator_functionality PASSED          [100%]

============================== 4 passed in 0.73s ===============================

Limitations

  • May not work with all Python packages
  • Dynamic code execution (eval, exec) may have limited optimization
  • Cross-platform compatibility requires recompilation
  • Initial compilation can be time-consuming for large projects

Troubleshooting

Common Issues

  1. Compilation fails: Ensure you have all required system dependencies installed
  2. Binary not found: Check that patchelf is installed on Linux systems
  3. Permission denied: Make sure the binary has execute permissions

Getting Help

If you encounter issues:

  1. Check that all system dependencies are installed
  2. Ensure you have the latest version of PySpeedBoost
  3. Check the Nuitka documentation for compilation issues

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please file an issue on our GitHub repository.# pyspeedboost

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

pyspeedboost-0.2.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

pyspeedboost-0.2.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pyspeedboost-0.2.0.tar.gz.

File metadata

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

File hashes

Hashes for pyspeedboost-0.2.0.tar.gz
Algorithm Hash digest
SHA256 55e8a148e0d05497548c3d166777e98b0d7d1329199efda9ef498ad1770b39a6
MD5 8967f7659f8bba462bc1c3a722038ecc
BLAKE2b-256 a98dd9d860faadb118f686f20bae245388ab81aa3d780b07935009c7bd9ea92b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyspeedboost-0.2.0.tar.gz:

Publisher: python-publish.yml on Chrispin-m/pyspeedboost

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

File details

Details for the file pyspeedboost-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyspeedboost-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyspeedboost-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a7fd861b500c06a708d30c723b04c05370d04a4be1b7ff193f7195595c56da4
MD5 cc6cd871bf77acedf86836c692010f6d
BLAKE2b-256 f6f9bd0bfbf2478839352c3cc2189f8f59c908c2828b0bb4c298842cccd921c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyspeedboost-0.2.0-py3-none-any.whl:

Publisher: python-publish.yml on Chrispin-m/pyspeedboost

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