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.
For example, this Python code:
def factorial(n):
if n <= 1:
return 1
else:
return n * factorial(n - 1)
Can be compressed to:
ƒfactorialn⟨⋔n≤#1⟨⇐#1⟩⋮⇐n*factorialn-#1⟩
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
Using pip:
pip install phiton
Using uv (recommended for faster installation):
uv 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 example.py
Read from stdin and write to stdout:
cat example.py | python -m phiton > example.phi
Preview compression without saving:
python -m phiton example.py --preview
Compress with specific options:
python -m phiton example.py --level=3 --comments=False --type-hints=False
Compress an entire directory:
python -m phiton 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)
# a file
stats = compress_file("example.py", "example.phi", config)
Compression Levels
Phiton offers 5 compression levels:
- Basic: Minimal symbol substitution, preserves structure and readability
- Moderate: More symbol substitutions while maintaining readability
- Standard: Full symbol substitution with some structure preservation
- High: Aggressive symbol substitution and minimal structure
- 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
-
Clone the repository:
git clone https://github.com/twardoch/phiton.git cd phiton
-
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phiton-1.0.3.tar.gz.
File metadata
- Download URL: phiton-1.0.3.tar.gz
- Upload date:
- Size: 299.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d29ff8e0bb3bf80667709e4a69900363ac36b8456a387c315f5e3edc448dafd
|
|
| MD5 |
2ea8249346e3d4269da249203cd8acc9
|
|
| BLAKE2b-256 |
c5f059b811ec11fd034a5d4e8e00f386025370ab024624eadf581317ebfe1529
|
File details
Details for the file phiton-1.0.3-py3-none-any.whl.
File metadata
- Download URL: phiton-1.0.3-py3-none-any.whl
- Upload date:
- Size: 21.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c862784185975bfd455ae47535676d022c7ccd2a1168b9d69f9be627e4b26a0
|
|
| MD5 |
cc4e2e4757ce5bec27a3073b41083d63
|
|
| BLAKE2b-256 |
df7d135f00f538f2d382d8e170c28b65413ea427fd6f460fa033268bc03ebe9c
|