Skip to content

Quynah/ape-lang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

APE Language β€” Monorepo

A deterministic AI-first programming language designed for unambiguous human-AI collaboration.

PyPI version Tests License


πŸ“¦ Packages

Core Language

packages/ape/ - APE compiler, runtime, and standard library

pip install ape-lang
  • βœ… 660 passing, 71 skipped (standalone runtime + full stdlib + decision engine)
  • βœ… Standalone execution engine (AST-based interpreter, no Python eval/exec)
  • βœ… Complete native stdlib (JSON, DateTime, Collections, Math, Strings, Logic)
  • βœ… Runtime-active decision logic (decision tables, policies, rules, constraints)
  • βœ… Multi-language support (7 languages: EN, NL, FR, DE, ES, IT, PT)
  • βœ… Runtime observability (tracing, explanation, replay, dry-run)
  • πŸ“– Full documentation β†’

How to run APE programs:

ape run file.ape --input data.json --output result.json

AI Integration Packages

packages/ape-anthropic/ - Anthropic Claude integration

pip install ape-anthropic
  • Executor and schema for Claude API
  • 49 tests passing

packages/ape-openai/ - OpenAI GPT integration

pip install ape-openai
  • Executor and schema for OpenAI API
  • 49 tests passing

packages/ape-langchain/ - LangChain integration

pip install ape-langchain
  • APE-to-LangChain bridge utilities
  • 20 tests (17 passing + 3 documented skips)

πŸš€ Quick Start

Installation

pip install ape-lang

Your First APE Program

Create hello.ape:

module hello

task greet:
    inputs:
        name: String
    outputs:
        message: String
    
    constraints:
        - deterministic
    
    steps:
        - set message to "Hello, " + name + "!"
        - return message

Run It

# Validate syntax and semantics
ape validate hello.ape

# Compile to Python
ape compile hello.ape

# Run with Python backend
ape run hello.ape

Use Programmatically

from ape import compile

# Compile APE source
module = compile("hello.ape")

# Call tasks
result = module.call("greet", name="World")
print(result)  # "Hello, World!"

πŸ§ͺ Test Suite Overview

βœ… All core tests passing

Component Tests Status
APE Core 611 βœ… 539 passing, 72 skipped
Anthropic Adapter 49 βœ… 49 passing
OpenAI Adapter 49 βœ… 49 passing
LangChain Adapter 20 βœ… 17 passing, 3 skipped
Total 729 βœ… 654 passing, 75 skipped

See packages/ape/docs/APE_TESTING_GUARANTEES.md for details on what these tests guarantee.

Test coverage includes:

  • Parser, lexer, and AST generation
  • Linker and module resolution system
  • Code generator and Python transpilation
  • Standard library functions (86 functions)
  • Runtime execution with control flow
  • Observability and introspection
  • Multi-language support (7 languages)
  • Tuple returns and list operations
  • Provider-specific adapters (Anthropic, OpenAI, LangChain)

Evidence-based counting: All numbers derived from pytest --collect-only discovery. No manual counting.

To regenerate counts:

python scripts/count_tests.py

🎯 Core Philosophy

"What is allowed, is fully allowed.
What is forbidden, is strictly forbidden.
What is not declared, does not exist."

APE is designed for deterministic execution and unambiguous communication between humans and AI:

  • βœ… Explicit over implicit - No magic behavior
  • βœ… Fail loud, fail fast - Clear errors, no guessing
  • βœ… Deterministic by default - Same input β†’ same output, always
  • βœ… AI-friendly syntax - Consistent structure for reliable code generation
  • βœ… Dual-purpose design - Bridge language (translator) + standalone language

πŸ“Š Repository Structure

ape-lang/
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ ape/                    # Core language compiler & runtime
β”‚   β”‚   β”œβ”€β”€ src/ape/           # Source code
β”‚   β”‚   β”œβ”€β”€ tests/             # 439 tests
β”‚   β”‚   β”œβ”€β”€ docs/              # Documentation (300+ pages)
β”‚   β”‚   β”œβ”€β”€ ape_std/           # Standard library
β”‚   β”‚   └── examples/          # Example programs
β”‚   β”œβ”€β”€ ape-anthropic/         # Anthropic integration
β”‚   β”œβ”€β”€ ape-openai/            # OpenAI integration
β”‚   └── ape-langchain/         # LangChain integration
β”œβ”€β”€ demo_*.ape                 # Demo programs
└── generated/                 # Generated code output

πŸ§ͺ Testing

APE includes a comprehensive runtime test suite covering:

  • Core type system (Record, Map, List, Value)
  • DateTime & Duration semantics (ISO-8601, UTC, arithmetic)
  • Collection and aggregation primitives (group_by, unique, max/min, any/all)
  • JSON / nested data access (dotted path navigation)

Run All Tests

# Run core language tests (523+ tests)
cd packages/ape
pytest

# Run Decision Engine validation
pytest tests/test_datetime.py tests/test_collections.py tests/test_json_path.py

# Run integration tests
cd packages/ape-anthropic
pytest

Test Results: See TEST_RESULTS.md for detailed validation evidence.


πŸ“– Documentation


🌍 Multi-Language Support

Write APE using keywords from your native language:

# English (canonical)
task calculate:
    inputs: x: Integer
    steps:
        if x > 0:
            - return x * 2

# Dutch
taak berekenen:
    invoer: x: Integer
    stappen:
        als x > 0:
            - return x * 2

# French
tΓ’che calculer:
    entrΓ©es: x: Integer
    Γ©tapes:
        si x > 0:
            - return x * 2

All produce identical AST and runtime behavior.


πŸ”— Links


πŸ“„ License

MIT License - see LICENSE for details.


πŸ‘€ Author

David Van Aelst


🦍 Status: v1.0.3

Current Release: v1.0.3 (December 2024)
Maturity: Production-ready core, scaffolded advanced features
Tests: 611/611 passing βœ…

See CHANGELOG for version history - guest

task CreateUser: inputs: username: String email: String role: UserRole outputs: user: User steps: - validate username is not empty - validate email format - create User instance - assign role to user - return user constraints: - username must be unique

flow UserRegistrationFlow: steps: - receive registration request - call CreateUser task - send welcome email - return success

policy SecurityPolicy: rules: - all passwords must be hashed - user data must be encrypted


## Usage

### Complete Pipeline

```python
from apeparser import parse_ape_source, IRBuilder
from apecompiler.semantic_validator import SemanticValidator
from apecompiler.strictness_engine import StrictnessEngine
from apecodegen.python_codegen import PythonCodeGenerator
from apecompiler.ir_nodes import ProjectNode

# 1. Parse Ape source
ast = parse_ape_source(source, "example.ape")

# 2. Build IR
builder = IRBuilder()
ir_module = builder.build_module(ast, "example.ape")
project = ProjectNode(name="MyProject", modules=[ir_module])

# 3. Validate
validator = SemanticValidator()
errors = validator.validate_project(project)

# 4. Check strictness
engine = StrictnessEngine()
warnings = engine.enforce(project)

# 5. Generate Python
codegen = PythonCodeGenerator(project)
files = codegen.generate()

# 6. Save
for file in files:
    with open(file.path, 'w') as f:
        f.write(file.content)

Running Demos

# Complete pipeline demo
python demo_pipeline.py

# Generate code
python example_generate.py

# Run tests
python -m pytest tests/ -v

# Test calculator example
python -m pytest tests/examples/test_calculator_basic.py -v

Examples

Calculator Examples

1. Calculator Basic (calculator_basic.ape)

A fully deterministic calculator example that demonstrates:

  • Strict type checking without ambiguity
  • Deterministic constraints
  • No controlled deviation
  • Complete pipeline from Ape β†’ Python

2. Calculator Smart (calculator_smart.ape)

Demonstrates the Controlled Deviation System (CDS):

  • Deterministic for calculations
  • Creative freedom for human summary
  • Explicit bounds define what can vary
  • Rationale explains why deviation is needed

See examples/calculator_basic.ape, examples/calculator_smart.ape and examples/README.md for details.

Test Results

βœ… Parser tests:           11 passed
βœ… Semantic tests:         19 passed
βœ… Codegen tests:          12 passed
βœ… Example tests:          14 passed (7 basic + 7 smart)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   TOTAL:                  56 passed

What Makes Ape Unique

  1. Strict Determinism - No implicit ambiguity allowed
  2. Controlled Deviation (RFC-0001) - Explicit flexibility with bounds
  3. AI-Native - Designed for AI agents to work with
  4. Type Safety - Strict type checking at all levels
  5. Policy Enforcement - Policy rules integrated in the language

Next Steps

Potential extensions:

  • Fully implement deviation system
  • Runtime with logging and tracing
  • Web-based playground
  • VS Code extension
  • More target languages (TypeScript, Rust, etc.)
  • Standard library with common patterns
  • Package manager for Ape modules

Technical Details

  • Language: Python 3.11+
  • Dependencies: None (stdlib only)
  • Test Framework: pytest
  • Code Style: Typed Python with dataclasses

Status: 🟒 Prototype v0.1 - Parser, Validator & Python Codegen working

Date: December 3, 2025

Author: Author: David Van Aelst (APE Creator)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors

Languages