PyBrKarma - Python with Braces Runtime Transformer
Project description
PyBrKarma ๐โจ
PyBrKarma is a sophisticated Python runtime transformer that enables developers to write Python code using curly braces ({ and }) instead of traditional colons and indentation. This bridges the syntactic gap between Python and C-style languages while maintaining full Python compatibility and semantics.
๐ฏ Overview
PyBrKarma transforms brace-delimited Python code into standard Python syntax at runtime, allowing developers familiar with C, Java, JavaScript, or other brace-based languages to write Python with familiar block delimiters. The transformation is transparent and maintains complete Python functionality.
Before (Standard Python)
def fibonacci(n):
if n <= 1:
return n
else:
return fibonacci(n-1) + fibonacci(n-2)
After (PyBrKarma Syntax)
def fibonacci(n) {
if n <= 1 {
return n
} else {
return fibonacci(n-1) + fibonacci(n-2)
}
}
๐ Key Features
- ๐ Runtime Transformation: Seamlessly converts
.pybrfiles to valid Python syntax - ๐ฆ Import System Integration: Import
.pybrmodules directly in Python code - ๐ ๏ธ CLI Tools: Run and convert
.pybrfiles from the command line - ๐ฏ Complete Language Support: Supports all Python control structures and constructs
- โก Zero Dependencies: Lightweight implementation with no external dependencies
- ๐ง Non-Intrusive: No modifications to the Python interpreter required
Supported Constructs
- Function definitions (
def) - Class definitions (
class) - Conditional statements (
if,elif,else) - Loop constructs (
for,while) - Exception handling (
try,except,finally) - Context managers (
with) - Pattern matching (
match,case) - Python 3.10+ - Lambda expressions and comprehensions
- Async/await syntax
๐ฆ Installation
Install PyBrKarma from PyPI using pip:
pip install pybrkarma
Requirements
- Python 3.6 or higher
- No external dependencies
๐ง Usage
Command Line Interface
Execute PyBrKarma Files
# Run a .pybr file directly
pybrkarma script.pybr
# Run with arguments
pybrkarma script.pybr arg1 arg2
# Alternative syntax
python -m pybrkarma script.pybr
Convert to Standard Python
# Convert .pybr to .py (outputs to stdout)
pybrkarma script.pybr --convert
# Convert and save to file
pybrkarma script.pybr --convert --output script.py
# Convert with custom output name
pybrkarma input.pybr -c -o output.py
Programmatic Usage
Import Hook Integration
from pybrkarma import enable_pybr_imports
# Enable .pybr file imports
enable_pybr_imports()
# Now you can import .pybr files as regular modules
import my_pybr_module
from my_package import my_pybr_submodule
# Disable when no longer needed
from pybrkarma import disable_pybr_imports
disable_pybr_imports()
Direct Transformation
from pybrkarma import transform_code
pybr_code = """
def greet(name) {
if name {
print(f"Hello, {name}!")
} else {
print("Hello, World!")
}
}
"""
python_code = transform_pybr(pybr_code)
exec(python_code)
๐ Project Architecture
pybrkarma/
โโโ pybrkarma/
โ โโโ __init__.py
โ โโโ __main__.py
โโโ setup.py
โโโ README.md
โโโ LICENSE
โโโ CHANGELOG.md
๐งช Examples
Basic Function Definition
# fibonacci.pybr
def fibonacci(n) {
if n <= 1 {
return n
}
return fibonacci(n-1) + fibonacci(n-2)
}
for i in range(10) {
print(f"fib({i}) = {fibonacci(i)}")
}
Class Definition
# shapes.pybr
class Rectangle {
def __init__(self, width, height) {
self.width = width
self.height = height
}
def area(self) {
return self.width * self.height
}
def perimeter(self) {
return 2 * (self.width + self.height)
}
}
rect = Rectangle(5, 3)
print(f"Area: {rect.area()}")
print(f"Perimeter: {rect.perimeter()}")
Exception Handling
# error_handling.pybr
def safe_divide(a, b) {
try {
result = a / b
return result
} except ZeroDivisionError {
print("Cannot divide by zero!")
return None
} finally {
print("Division operation completed")
}
}
๐ Advanced Features
Context Managers
# file_operations.pybr
def read_file(filename) {
try {
with open(filename, 'r') as f {
return f.read()
}
} except FileNotFoundError {
print(f"File {filename} not found")
return None
}
}
Pattern Matching (Python 3.10+)
# pattern_matching.pybr
def handle_data(data) {
match data {
case {'type': 'user', 'name': str(name)} {
print(f"User: {name}")
}
case {'type': 'admin', 'permissions': list(perms)} {
print(f"Admin with permissions: {perms}")
}
case _ {
print("Unknown data format")
}
}
}
๐งช Testing
Run the test suite:
# Install development dependencies
pip install -e .[dev]
# Run tests
python -m pytest tests/
# Run with coverage
python -m pytest tests/ --cov=pybrkarma
๐ค Contributing
We welcome contributions! Please follow these guidelines:
- Fork the repository and create a feature branch
- Write tests for new functionality
- Follow PEP 8 coding standards
- Update documentation as needed
- Submit a pull request with a clear description
๐ Performance
PyBrKarma introduces minimal overhead:
- Transformation time: ~0.1ms per 1000 lines of code
- Memory usage: <1MB additional memory per imported module
- Runtime performance: Identical to standard Python (no runtime overhead)
๐ ๏ธ Troubleshooting
Common Issues
Import errors with .pybr files:
# Make sure to enable imports first
from pybrkarma import enable_pybr_imports
enable_pybr_imports()
Syntax errors in transformation:
- Ensure proper brace matching
- Check that all control structures use braces
- Verify Python syntax is otherwise valid
Debug Mode
Enable debug output:
import pybrkarma
pybrkarma.set_debug(True)
๐ Links & Resources
- ๐ฆ PyPI Package: https://pypi.org/project/pybrkarma/
- ๐ GitHub Repository: https://github.com/Salehin-07/pybrkarma
- ๐ Documentation: https://pybrkarma.readthedocs.io/
- ๐ Issue Tracker: https://github.com/Salehin-07/pybrkarma/issues
- ๐ฌ Discussions: https://github.com/Salehin-07/pybrkarma/discussions
๐จโ๐ป Author
Md Abu Salehin
- ๐ GitHub: @Salehin-07
- ๐ง Email: mdabusalehin123@gmail.com
- ๐ Website: https://salehin.dev
๐ License
This project is licensed under the MIT License. See the LICENSE file for details.
๐ Acknowledgments
- Inspired by the need to bridge syntax preferences across programming languages
- Thanks to the Python community for feedback and contributions
- Special thanks to all contributors and early adopters
Enjoy writing Python with the familiar comfort of curly braces! ๐โจ
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 pybrkarma-1.1.1.tar.gz.
File metadata
- Download URL: pybrkarma-1.1.1.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d90b5cbc26df6b873050644329f3d9faaa5a1052ff1c27f33373db57eea16f7
|
|
| MD5 |
db172db45f8cbd7646e70e97d91e3da4
|
|
| BLAKE2b-256 |
97d7af59774a431889d97521a1ea5c6efcd47aff60fe43f964a5a548d37447f4
|
File details
Details for the file pybrkarma-1.1.1-py3-none-any.whl.
File metadata
- Download URL: pybrkarma-1.1.1-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53bf2e83029c5cb7d19bc6362665ef7aae8b232de82a65391ed230a5055edd33
|
|
| MD5 |
501ae6ed431ffcd0419c03f2f284efdb
|
|
| BLAKE2b-256 |
690ffcf26dcc1ec37ae21a5fe8dd1bf42ef1d225f6ad1a60f0617497b003fad4
|