Skip to main content

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.

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:

  1. Safety: As expected in modern programming languages, Typhon enforces safety through static typing, lexical scopes, immutable-by-default variables (let), and null safety features (?., ??, ?(), ?[]).
  2. 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.
  3. 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

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) or var (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 |> f for 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)). All if/while/for/let/try/with/match are supported as comprehension. See Comprehensions.
  • Pattern Matching: Enhanced match, if-let, and let-else statements. See Control Flow.
  • self Keyword: self is 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: &&, ||, ! replace and, 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

typhon_language-0.1.4.tar.gz (126.9 kB view details)

Uploaded Source

Built Distribution

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

typhon_language-0.1.4-py3-none-any.whl (146.9 kB view details)

Uploaded Python 3

File details

Details for the file typhon_language-0.1.4.tar.gz.

File metadata

  • Download URL: typhon_language-0.1.4.tar.gz
  • Upload date:
  • Size: 126.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for typhon_language-0.1.4.tar.gz
Algorithm Hash digest
SHA256 9986bda3896923bca8612c86008c0062f35d4360fffde81097423a3ddd470535
MD5 4c79811d2cf5bbc8776a95b2a6491a30
BLAKE2b-256 3f38c559ea12d9ede7c42f81504b9f570ceacc2220db81863fb8bcb62e7744f5

See more details on using hashes here.

File details

Details for the file typhon_language-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for typhon_language-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 203887f52647f2f34e50bcded766d4f235394902f16808cd7a35247a81c6fad6
MD5 a3fe7bdfafb4eb4e5010cd4a8bd1a5f4
BLAKE2b-256 69c09fe7dd205c9fe1d1c7847a3c3e6b0cdd86b324291a4c1b9125d3a5dca51d

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