Skip to main content

No project description provided

Project description

Phiton

Phiton is a Python code compressor that converts standard Python code into a more concise notation using mathematical symbols and advanced compression techniques.

Features

  • Convert Python code to a compressed symbolic notation
  • Adjustable compression levels (1-5)
  • Preserve comments and type hints (optional)
  • Command-line interface with rich output
  • Support for processing individual files or entire directories
  • Detailed compression statistics

Installation

pip install phiton

Or install directly from the repository:

pip install git+https://github.com/twardoch/phiton.git

For development, you can install with extras:

# Install with development dependencies
pip install -e ".[dev]"

# Install with testing dependencies
pip install -e ".[test]"

# Install with all dependencies
pip install -e ".[all]"

Usage

Command Line

Compress a Python file:

python -m phiton compress example.py

Preview compression without saving:

python -m phiton compress example.py --preview

Compress with specific options:

python -m phiton compress example.py --level=3 --comments=False --type-hints=False

Compress an entire directory:

python -m phiton compress my_project/ --output-path=compressed/

Show version:

python -m phiton version

Python API

from phiton import compress_string, compress_file, ConversionConfig

# Basic usage
result = compress_string("def hello(name: str) -> str:\n    return f'Hello, {name}!'")
print(result["result"])  # Compressed code
print(result["stats"])   # Compression statistics

# With custom configuration
config = ConversionConfig(
    level=3,             # Compression level (1-5)
    comments=False,      # Don't preserve comments
    type_hints=True,     # Preserve type hints
    minify=True,         # Minify the code
    symbols=True,        # Use symbol substitution
)
result = compress_string("def hello(name: str) -> str:\n    return f'Hello, {name}!'", config)

# Compress a file
stats = compress_file("example.py", "example.phi", config)

Compression Levels

Phiton offers 5 compression levels:

  1. Basic: Minimal symbol substitution, preserves structure and readability
  2. Moderate: More symbol substitutions while maintaining readability
  3. Standard: Full symbol substitution with some structure preservation
  4. High: Aggressive symbol substitution and minimal structure
  5. Maximum: Highest compression with shortest possible representation

Symbol Examples

Python Phiton Description
def ƒ Function definition
return Return statement
if Conditional
for For loop
in Membership test
None None value
True True value
False False value
and Logical AND
or Logical OR
not ¬ Logical NOT
== Equality
!= Inequality
<= Less than or equal
>= Greater than or equal
= Assignment

Project Structure

phiton/
├── examples/           # Example files for testing
├── src/
│   └── phiton/         # Main package
│       ├── __init__.py # Package entry point
│       ├── __main__.py # CLI entry point
│       ├── cli.py      # Command-line interface
│       ├── config.py   # Configuration dataclass
│       ├── constants.py # Symbol mappings
│       ├── converter.py # Core conversion logic
│       └── utils.py    # Utility functions
└── tests/              # Test suite
    ├── data/           # Test data files
    ├── test_cli.py     # CLI tests
    ├── test_config.py  # Configuration tests
    ├── test_converter.py # Converter tests
    └── test_utils.py   # Utility tests

Development

Setup

  1. Clone the repository:

    git clone https://github.com/twardoch/phiton.git
    cd phiton
    
  2. Create and activate a virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install development dependencies:

    pip install -e ".[dev,test]"
    

Testing

Run the tests:

python -m pytest

Run with coverage:

python -m pytest --cov=src/phiton

Linting

Run the linter:

ruff check .

Fix linting issues:

ruff check --fix --unsafe-fixes .

Format the code:

ruff format .

License

MIT License

Contributing

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

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

phiton-1.0.1.tar.gz (263.5 kB view details)

Uploaded Source

Built Distribution

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

phiton-1.0.1-py3-none-any.whl (41.5 kB view details)

Uploaded Python 3

File details

Details for the file phiton-1.0.1.tar.gz.

File metadata

  • Download URL: phiton-1.0.1.tar.gz
  • Upload date:
  • Size: 263.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.1

File hashes

Hashes for phiton-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3a0f67c306bd22ffaf8174e890b23eefd375ba400b0a80133b3e8e66057b6c66
MD5 a81a5536277accc786fb7938573f4df9
BLAKE2b-256 458f7ba1b4b9c1eb01cf8548609229e54bf1009337ca16aec217ee2232ce8a72

See more details on using hashes here.

File details

Details for the file phiton-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: phiton-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 41.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.1

File hashes

Hashes for phiton-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 be29ebf3946cd74d022af7183209f75e82979a1bf9416899ab60de97cd94f48f
MD5 a211ad1c085cbba0a9c6b00dcbf1e4a6
BLAKE2b-256 6dd13059eb2f1d5842556a3036be57800d2ba8d14fbd2cdd2eef3b6c1fcb0923

See more details on using hashes here.

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