Ape โ The Because-I-Said-So Language for deterministic AI programming
Reason this release was yanked:
Wrong version number
Project description
Ape - AI Programming Language
The very first AIP (AI Programming Language) ๐
Ape is an AI-native programming language with a strict core and Controlled Deviation System.
Quickstart
Installation
git clone https://github.com/yourusername/ape.git
cd ape
pip install -r requirements.txt # if exists, or install pytest
CLI Usage
# Parse Ape source to AST
python -m ape parse examples/calculator_basic.ape
# Build IR (Intermediate Representation)
python -m ape ir examples/calculator_basic.ape
# Validate semantics and strictness
python -m ape validate examples/calculator_basic.ape
# Build Python code
python -m ape build examples/calculator_basic.ape --target=python
Your First Ape Program
Create hello.ape:
entity Greeting:
message: String
task say_hello:
inputs:
- name: String
outputs:
- greeting: Greeting
constraints:
- deterministic
steps:
- create greeting with message
- return greeting
Then compile it:
python -m ape validate hello.ape
python -m ape build hello.ape --target=python
Core Philosophy
"What is allowed, is fully allowed.
What is forbidden, is strictly forbidden.
What is not declared, does not exist."
What is Implemented
โ 1. Parser & Tokenizer
- Tokenizer with indentation-aware lexical analysis
- AST nodes for all Ape constructs
- Recursive descent parser for Ape grammar v0.3
- IR Builder transforms AST to Intermediate Representation
Tests: 11 passing
โ 2. Semantic Validator
- Symbol table for tracking all declarations
- Type checking (entities, enums, builtin types)
- Duplicate definition detection
- Unknown type detection
- Contract validation
- Policy validation
- Deviation validation (RFC-0001)
โ 3. Strictness Engine
- Ambiguity detection (maybe, possibly, ?, etc.)
- Undeclared behavior detection
- Implicit choice detection (or, choose, etc.)
- Non-determinism detection (random, etc.)
- Deviation bounds validation
- Policy conflict detection
Tests: 19 passing
โ 4. Python Code Generator
- Entity โ Python @dataclass with type hints
- Enum โ Python constants class
- Task โ Python function with documentation
- Flow โ Orchestration function + metadata
- Policy โ Python dict structures
- Syntactically valid Python output
Tests: 12 passing
โ 5. Runtime Support
- RunContext for flow orchestration
- Placeholder for logging, determinism, etc.
Project Structure
Ape/
โโโ src/
โ โโโ apeparser/ # Parser & Tokenizer
โ โ โโโ tokenizer.py
โ โ โโโ parser.py
โ โ โโโ ast_nodes.py
โ โ โโโ ir_builder.py
โ โโโ apecompiler/ # Compiler & Validation
โ โ โโโ ir_nodes.py
โ โ โโโ errors.py
โ โ โโโ semantic_validator.py
โ โ โโโ strictness_engine.py
โ โโโ apecodegen/ # Code Generation
โ โ โโโ python_codegen.py
โ โโโ aperuntime/ # Runtime Support
โ โโโ core.py
โโโ tests/ # Test Suite (49 tests)
โ โโโ parser/
โ โโโ compiler/semantic/
โ โโโ codegen/python/
โ โโโ examples/ # Example program tests
โโโ examples/ # Example Ape programs
โ โโโ calculator_basic.ape
โ โโโ README.md
โโโ generated/ # Generated Python code
โโโ demo_pipeline.py # Complete pipeline demo
โโโ example_generate.py # Code generation example
Ape Syntax Voorbeeld
entity User:
id: Integer
username: String
email: String
enum UserRole:
- admin
- user
- 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
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
- Strict Determinism - No implicit ambiguity allowed
- Controlled Deviation (RFC-0001) - Explicit flexibility with bounds
- AI-Native - Designed for AI agents to work with
- Type Safety - Strict type checking at all levels
- 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
Technische Details
- Taal: Python 3.11+
- Dependencies: Geen (stdlib only)
- Test Framework: pytest
- Code Style: Typed Python met dataclasses
Status: ๐ข Prototype v0.1 - Parser, Validator & Python Codegen working
Date: December 3, 2025
Author: David Van Aelst (Creator & Lead Designer)
Project details
Release history Release notifications | RSS feed
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 ape_lang-0.1.3.tar.gz.
File metadata
- Download URL: ape_lang-0.1.3.tar.gz
- Upload date:
- Size: 29.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f93923cdc69657d29397667747af2fb1eadf00675cf1931b79b55910ea559772
|
|
| MD5 |
0c03c0474401a7c99fa98dfe99766c1c
|
|
| BLAKE2b-256 |
02e9932b8520b577c7f0cff48412f73b268e655b2f4853828fcc0d5a10abf827
|
File details
Details for the file ape_lang-0.1.3-py3-none-any.whl.
File metadata
- Download URL: ape_lang-0.1.3-py3-none-any.whl
- Upload date:
- Size: 32.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c6d2ce42a15cd82954551860e85d238565a90dca58613d949001bbb107fb2ce
|
|
| MD5 |
ce163ca7170a6a98bdb67f2fb4e6eb1b
|
|
| BLAKE2b-256 |
18bff29ae832d209f4dcbd3ee4dc8a44407196ce32add5d1d6644b959b6127d3
|