Typhon programming language
Project description
Typhon
Typhon is a modernized syntax sugar for Python, designed to improve developer experience with features like static typing, brace-based scoping, and expressive functional programming capabilities.
- GitHub repository: Typhon
- PyPI package: Typhon-Language
- VSCode extension: Typhon Language Support from GitHub Repository
Getting Started
Install Typhon via pip:
pip install typhon-language
Run Typhon from the command line:
typhon --help
Create a simple Typhon program in hello.typh:
def main() {
print("Hello, Typhon!")
}
main()
Run the program:
typhon run hello.typh
Or run directly using uvx:
uvx --from typhon-language typhon run hello.typh
Design Concepts
Typhon is built on three core pillars:
- Safety: As expected in modern programming languages, Typhon enforces safety through static typing, lexical scopes, immutable-by-default variables (
let), and null safety features (?.,??,?(),?[]). - Expressiveness: Expression-oriented design with functional programming features. Control comprehension forms for
if,match,try, and so on enable concise, value-returning expressions. Function literals, placeholders and pipe operators facilitate clean and readable code. - Python Interoperability: Typhon compiles directly to Python, allowing you to use the vast ecosystem of Python libraries seamlessly while enjoying a modern syntax.
How it looks like
You can see small code snippets in the test directory: Typhon Tests.
Documentation
For a complete guide to the language, please visit the Typhon Reference Manual.
Quick Links
- Lexical Structure (Comments, Keywords, Delimiters)
- Types
- Variables
- Expressions
- Statements
- Definitions (Functions, Classes, Modules)
- Removed Features
Syntax Changes from Python
Typhon retains most of Python's semantics but introduces significant syntax changes.
Main Changes
- Brace Scoping: Typhon uses
{ ... }for blocks, replacing indentation-based scoping. Both;and line breaks can also act as delimiters. See Lexical Structure for more details. - Static Typing: Type checking is enforced at compile time. Currently powered by basedpyright type checker.
- Declarations: Variables must be declared with
let(immutable) orvar(mutable). See Variables.
Syntax Extensions
- Null Safety:
?.,??,?(),?[]operators. See Null Safety. - Function literals: Unrestricted function literals with
(x) => { return x + 1 }syntax, with totally the same capability as normal functions. SeeFunction literals. - Pipe Operator:
x |> ffor function chaining. See Pipe Operator. - Placeholders:
_for concise anonymous functions (e.g.,_ + 1). See Placeholders. - Control Comprehensions: Control statements as expressions (e.g.,
(if (c) x else y)). Allif/while/for/let/try/with/matchare supported as comprehension. See Comprehensions. - Pattern Matching: Enhanced
match,if-let, andlet-elsestatements. See Control Flow. selfKeyword:selfis a keyword and is not explicitly declared in method signatures. See Classes.- Data Records: Anonymous immutable structs
{|x=1|}. See Types. - Block Comments:
#( ... )#allows nested comments.
Detailed Design Changes
- Logical Operators:
&&,||,!replaceand,or,not(though Python keywords are still reserved). - Const Parameters: Function parameters are immutable by default.
- Line Breaks: Stricter rules for line continuations. See Lexical Structure.
Syntax Restrictions
Some Python features are removed to enforce safety and clarity. See Removed Features.
- No
del,global,nonlocal. - No wildcard imports.
- No chained assignments (
a = b = c). - No control statements inside class bodies.
Usage
Typhon can be run directly or translated to Python.
.typh files are Typhon source files. In directory mode, all .typh files are processed.
Note Typhon uses .typhon directory in source paths to place translated Python files and caches.
Run
Run a Typhon source file or directory.
typhon run <source> [args...]
Translate
Translate Typhon code to Python.
typhon translate <source> [-o output_dir]
Type Check
Run type checking on Typhon code.
typhon type_check <source>
Future Plans
See Future Plans for planned features like compile-time controls (static if) and known limitations.
Influenced By
Typhon draws inspiration from several modern programming languages:
- Python
- TypeScript
- Swift
- Rust
- Scala
- F#
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 typhon_language-0.1.3.tar.gz.
File metadata
- Download URL: typhon_language-0.1.3.tar.gz
- Upload date:
- Size: 102.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6b784f57b50bd7defad48e46f4183c1e7cb69f9bcccb0336e1968b13f67fa4d
|
|
| MD5 |
6b3b6dbd9033c6d96bb44bd3db933d14
|
|
| BLAKE2b-256 |
9650c7bc5949885f4e0589dc0b9ff76b33b8fbe76adf484853bea8e400c1c23d
|
File details
Details for the file typhon_language-0.1.3-py3-none-any.whl.
File metadata
- Download URL: typhon_language-0.1.3-py3-none-any.whl
- Upload date:
- Size: 116.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05cb4d6e73b36932c7fbf6ffe189dab165b61dd4eac322366de2444cf3dd1965
|
|
| MD5 |
dda42003b529d5b22069b40530f7b488
|
|
| BLAKE2b-256 |
1b11a092751b0c66b630fc19098d54c0b0106f2748263b0d6609b25adf4d163d
|