Cypy
A Python-like language that compiles to Cython.
Features
- Python Compatibility: Partial Python syntax compatibility
- Gradual Typing: Annotated variables use static types, unannotated fall back to
object - Compile-time Checking:
cypyctranspiler catches type errors early - Cython Backend: Compiles to Cython for high-performance C code
- Modern Syntax: Pattern matching, enum, struct, trait, let/var, and more
- Concurrency:
gokeyword for coroutines,spawnfor threads - Pipe Operator:
|>for function chaining - List Comprehensions: Full support with nested loops and conditions
Quick Start
# Install dependencies
pip install -e .
# Transpile a Cypy file
cypyc input.cypy
# Transpile and compile
cypyc --compile input.cypy
# Type check only
cypyc --check input.cypy
Syntax Examples
Structs
struct Point:
x: float
y: float
def distance(self, other: Point) -> float:
return ((self.x - other.x) ** 2 + (self.y - other.y) ** 2) ** 0.5
Pattern Matching
match value:
case 1:
return "one"
case (a, b):
return f"tuple: {a}, {b}"
case _:
return "other"
Enum
enum Color:
Red
Green
Blue
def process_color(c: Color) -> int:
match c:
case Color.Red:
return 1
case _:
return 0
Let/Var Variables
let x: int = 10 # Immutable, cannot be reassigned
var y: int = 20 # Mutable, can be reassigned
Pipe Operator
let result = 5 |> double |> square # equivalent to square(double(5))
Go (Coroutines) and Spawn (Threads)
let task = go fetch_data(url) # asyncio.create_task
let thread = spawn heavy_computation() # threading.Thread
List Comprehensions
let squares = [x ** 2 for x in range(10) if x % 2 == 0]
Documentation
- SYNTAX_IMPLEMENTATION_STATUS.md - 语法实现状态报告
- SYNTAX/00-introduction.md - 语言介绍
- SYNTAX/01-basic-types.md - 基础类型
- SYNTAX/02-type-annotations.md - 类型注解
- SYNTAX/05-struct.md - 结构体
- SYNTAX/06-enum.md - 枚举
- SYNTAX/07-trait-impl.md - 特质系统
- SYNTAX/09-functions.md - 函数
- SYNTAX/10-variables.md - 变量
- SYNTAX/20-concurrency.md - 并发
- SYNTAX/23-compilation.md - 编译系统
Project-Level Compilation
# Build entire project with cross-module type inference
cypyc build <project_directory>
# Build with specific entry point
cypyc build <project_directory> --entry main
# Type check only
cypyc build <project_directory> --check-only
Examples
Explore the examples/ directory for code examples:
- basic_types.cypy - Basic types and type conversion
- control_flow.cypy - Control flow statements
- functions.cypy - Functions and pipe operator
- struct_enum.cypy - Structs and enums
- concurrency.cypy - Coroutines and threads
- list_comprehension.cypy - List comprehensions
Testing
python scripts/run_tests.py
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cypyc-0.1.0.tar.gz
(338.1 kB
view details)
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
cypyc-0.1.0-py3-none-any.whl
(270.7 kB
view details)
File details
Details for the file cypyc-0.1.0.tar.gz.
File metadata
- Download URL: cypyc-0.1.0.tar.gz
- Upload date:
- Size: 338.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ada558433ce5081888df703906d28514970a1a32b0ad37674d68d3226020ea35
|
|
| MD5 |
7769d69f9360fc2ac950f18a3c5cde76
|
|
| BLAKE2b-256 |
249ff13d59d0841aec2f5d31c2bba8992918258e93442a4084603c3b25725d38
|
File details
Details for the file cypyc-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cypyc-0.1.0-py3-none-any.whl
- Upload date:
- Size: 270.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06470027f60998b149cfc4961076353de003ec00d2b9a7ce72d6fd46e8616f3d
|
|
| MD5 |
a6e78cfa7beb22b4b4e799d32efe48d0
|
|
| BLAKE2b-256 |
8db3633d1b2a46a8bd73ebae23607bf221f41e6c25ba6bf302b1b41bc293cef9
|