Skip to main content

A Python-inspired interpreter with real-time code analysis and optimization suggestions

Project description

OptiLang

A Python-inspired interpreter with real-time code analysis and optimization suggestions

Python Version License: MIT Code style: black


๐ŸŽฏ Project Overview

OptiLang is an educational interpreter for a Python-like language (PyLite) that provides:

  • Real-time code execution with line-by-line profiling
  • Optimization suggestions based on detected anti-patterns
  • Quantitative scoring (0-100) for code quality
  • Pattern detection for 8+ common performance issues

๐Ÿš€ Quick Start

Installation

pip install optilang

Basic Usage

from optilang import execute, analyze

# Execute PyLite code
result = execute("""
def factorial(n):
    if n <= 1:
        return 1
    return n * factorial(n - 1)

print(factorial(5))
""")

print(result.output)  # "120"
print(f"Execution time: {result.execution_time}ms")

# Analyze code for optimizations
report = analyze("""
for i in range(100):
    for j in range(100):
        result = i * j
""")

print(f"Optimization Score: {report.optimization_score}/100")
for suggestion in report.suggestions:
    print(f"Line {suggestion.line}: {suggestion.description}")

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Lexer   โ”‚ -> โ”‚  Parser  โ”‚ -> โ”‚ Executor โ”‚ -> โ”‚ Profiler โ”‚
โ”‚ (Tokens) โ”‚    โ”‚  (AST)   โ”‚    โ”‚ (Runtime)โ”‚    โ”‚ (Metrics)โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                       โ”‚              โ”‚
                                       v              v
                                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                 โ”‚Optimizer โ”‚    โ”‚  Scorer  โ”‚
                                 โ”‚(Patterns)โ”‚    โ”‚ (0-100)  โ”‚
                                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“‹ Features

Current (v0.1.0)

  • Lexical analysis (tokenization)
  • Syntax parsing (AST generation)
  • Code execution (variables, functions, control flow)
  • Basic profiling (execution time, line counts)

Planned

  • Advanced profiling (memory usage, call graphs)
  • 8+ optimization patterns
  • ML-based suggestion ranking (optional)
  • Optimization score calculation
  • Comprehensive documentation

๐Ÿ› ๏ธ Development Setup

# Clone repository
git clone https://github.com/Sthamanik/optilang.git
cd optilang

# Create virtual environment
conda create -n optilang python -y
conda activate optilang

# Install in editable mode with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black optilang/

# Type checking
mypy optilang/

# Linting
flake8 optilang/

๐Ÿ“š Documentation


๐Ÿงช Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=optilang --cov-report=html

# View coverage report
open htmlcov/index.html  # Linux/Mac
# or start htmlcov/index.html on Windows

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.


๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ‘ฅ Team


๐Ÿ“ง Contact

For questions or feedback:


โญ Star this repository if you find it useful!

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

optilang-0.1.0.tar.gz (38.1 kB view details)

Uploaded Source

Built Distribution

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

optilang-0.1.0-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file optilang-0.1.0.tar.gz.

File metadata

  • Download URL: optilang-0.1.0.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for optilang-0.1.0.tar.gz
Algorithm Hash digest
SHA256 99710da7bfc792bf1af0debcdbc5bd65567f0ee1643c0f9486bc1854e88a3f11
MD5 35dd4de9ac7943715ce851ca15c9a90e
BLAKE2b-256 89b15784809f8e8ca3829c3cb9bbda61936afa83cfdb8ea0b79ba739f4225061

See more details on using hashes here.

File details

Details for the file optilang-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: optilang-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for optilang-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 789ee2c62df0c5881c50d9b38680a32840876846be4739671b9e33096d14964d
MD5 4b6e0ae111eadae747d80fe0734fa979
BLAKE2b-256 dc4df310c09d7605894f3a05a611c40567ae5cc0ea05ae546cb943447fa704af

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