Skip to main content

Check out the official documentation here.

Package Extensions

Cpyte supports a package extension system that allows packages to extend the compiler with custom keywords, operators, and compiler hooks. Packages can provide:

  • Custom Keywords: Add new language keywords via package.json
  • Custom Operators: Define new operators for syntax extensions
  • Compiler Hooks: Extend lexing, parsing, semantic analysis, and code generation
  • Runtime Extensions: Add runtime code and libraries

Package Structure

Packages are stored in .cpm/modules/package_name/version/ and can include:

  • package.json - Extension manifest declaring capabilities
  • parser_hooks.py - Custom syntax extensions
  • semantic_hooks.py - Custom type checking and analysis rules
  • codegen_hooks.py - Custom LLVM IR generation
  • runtime_hooks.py - Runtime code and libraries
  • *.cpy - Main package entry point
  • *.ll - Prebuilt LLVM IR

Example Package

See examples/example_package/ for a complete example package with:

  • Custom keywords: async, await, defer
  • Custom operator: ~~
  • Parser, semantic, codegen, and runtime hooks

Using Extension Packages

import @package_name

# Use custom keywords and syntax from the package
async def my_function() -> Promise:
    # Custom syntax
    defer cleanup()
    return result

Examples

You'll find comprehensive examples in the examples/ directory that cover C imports, header imports, 64-bit support, and standard library usage:

File Description
examples/c_import_example.cpy Importing and calling functions from C source files
examples/example_math.c C source with math utility functions for the C import example
examples/h_import_example.cpy Importing functions declared in C header files
examples/example_functions.h / example_functions.c Header and implementation for the H import example
examples/64bit_example.cpy Comprehensive int64/uint64 arithmetic, hex literals, type promotion
examples/c_library_imports.cpy Using built-in C libraries (stdio, stdlib, math, string, time)
examples/mixed_features.cpy Combines C imports, H imports, 64-bit, structs, pointers, linked lists
examples/mixed_helpers.c / mixed_helpers.h Supporting C/header files for the mixed features example
examples/test.cpy macOS event tap example that intercepts keyboard events using ApplicationServices framework
examples/example_package/ Example package demonstrating extension capabilities with custom keywords, operators, and compiler hooks

You can also import .cpy files — the examples show how to use import "other.cpy" to bring in public functions and structs from other Cpy files.

Run any example with:

cpy examples/<filename>.cpy

Note

Cpyte is experimental software. The compiler is continuously tested with fuzzing and a regression corpus, and every release is published to PyPI and Gitea.

Memory Management

Cpyte uses a concurrent tri-color garbage collector for automatic memory management. Heap-allocated objects (via new) are managed automatically — no manual free needed.

Note: The collector adds a small runtime overhead (~5-10%) compared to manual malloc/free. For performance-critical ecosystem projects or embedded use cases, this trade-off may be significant. The GC is required for safety but will slow down programs that do heavy heap allocation.

Cross-Platform Runtime

The compiler is fully cross-platform. On every target OS (macOS, Linux, Windows) the C runtime (runtime.c), the GC runtime (gc_runtime.c), and any embedded ccode: blocks are compiled from source at JIT/AOT time for the host platform, rather than linking pre-built, OS-specific bitcode. This keeps native helpers and the garbage collector correct on each system:

  • Portable threading: pthread on POSIX; native Windows threads + CRITICAL_SECTION on Windows.
  • Portable stack scanning for the GC that works on macOS, Linux, and Windows.
  • A portable sleep/yield helper replaces the POSIX-only nanosleep.

The compiler auto-discovers a C compiler (clangccgcc) and system linker on the current platform, so cpy, cpy build, and cpy --aot all work without per-OS configuration.

Continuous Integration

GitHub Actions (see .github/workflows/code_quality.yml) builds and runs a curated, cross-platform regression corpus on Ubuntu (x86_64 + arm64), macOS (x86_64 + arm64), and Windows. ci_test.py AOT-compiles each program with the system linker and executes the result to exercise the full pipeline — lexer, parser, semantic analysis, LLVM codegen, the C and GC runtimes, and linking.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpyte-3.4.0.tar.gz (216.5 kB view details)

Uploaded Source

Built Distribution

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

cpyte-3.4.0-py3-none-any.whl (220.1 kB view details)

Uploaded Python 3

File details

Details for the file cpyte-3.4.0.tar.gz.

File metadata

  • Download URL: cpyte-3.4.0.tar.gz
  • Upload date:
  • Size: 216.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.7

File hashes

Hashes for cpyte-3.4.0.tar.gz
Algorithm Hash digest
SHA256 f8acdd0f41b01796a0e75f5679f1b9efa4a363afae0f94a5f4645024f1b55e98
MD5 6dc7f2f10dfd28a750e4ee4a2496e254
BLAKE2b-256 6173c40b1827f01a8202cb6d9c3c116f0782fb930cb8e23eee4279086f1a9a5f

See more details on using hashes here.

File details

Details for the file cpyte-3.4.0-py3-none-any.whl.

File metadata

  • Download URL: cpyte-3.4.0-py3-none-any.whl
  • Upload date:
  • Size: 220.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.7

File hashes

Hashes for cpyte-3.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b75cbfde17c536bd9bb0e168537b947765118d88b7fe0e7aea93d78bfe439211
MD5 9c8084e52be20752f1d0e493df7f0c81
BLAKE2b-256 91ade01f6edbb29a5a3a36b4a398755fce4e3d467824ef625e6a2d78460fd4f3

See more details on using hashes here.

Release history Release notifications | RSS feed

4.2.2

2 files

4.2.1

1 file

4.2.0

1 file

4.1.0

2 files

4.0.0

2 files

This release

3.4.0 This release

2 files

3.3.4

2 files

3.3.3

2 files

3.3.2

2 files

3.3.1

2 files

3.3.0

2 files

3.2.0

2 files

3.1.0

2 files

3.0.0

2 files

2.7.3

2 files

2.7.2

2 files

2.7.1

2 files

2.7.0

2 files

2.6.0

2 files

2.5.1

2 files

2.5.0

2 files

2.4.1

2 files

2.4.0

2 files

2.3.1

2 files

2.3.0

2 files

2.2.0

2 files

2.1.0

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

1.8.7

2 files

1.8.6

2 files

1.8.5

2 files

1.8.4

2 files

1.8.3

2 files

1.8.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page