PyFASM64: Universal Python-to-Pure FASM x86_64 Native Compiler
🤝 Community, Issues & Support
- 🐛 Found a bug, compiler issue, or edge case? Please Open an Issue — bug reports and platform patches are tracked and resolved quickly!
- 💬 Questions, cross-compilation ideas, or new architectures? Join our GitHub Discussions.
- ⭐ Find PyFASM64 useful? Give it a star on GitHub — it helps more developers discover the compiler!
- ☕ Support development (USDT TRC-20):
TDVbEdnpgNgoAhNcn1EwXxWHiR3RKLit5P(Verify on TronScan)
PyFASM64 (package: pyfasm64, legacy alias: pyfasm) is a high-performance cross-platform native compiler that translates Python code directly into pure x86_64 Flat Assembler (FASM) machine code. It generates tiny, self-contained standalone binaries with zero runtime overhead, no virtual machine, and complete elimination of the Global Interpreter Lock (Zero-GIL).
It supports hosting on CPython 3.8–3.16, Free-Threaded / No-GIL Python (3.13t–3.16t), and PyPy (3.8–3.12). PyFASM64 produces native binaries without external dependencies across native target formats: Windows (.exe, .dll), Linux (ELF64), and Apple macOS (Mach-O 64).
💡 100% Backward Compatibility: PyFASM64 preserves every existing capability and workflow of classic PyFASM:
- Dual CLI Commands: Both
pyfasm64andpyfasmcommands are installed and supported out of the box.- Dual Python Imports: Both
import pyfasm64andimport pyfasmwork seamlessly.- Zero Breaking Changes: All compiler options, multi-module imports, targets (
win64,linux,macos,dll), benchmarks, and the native bundler operate with complete backward compatibility.
Key Features
- True Zero-GIL Multithreading:
- Compiled executables run directly on bare metal without any Python VM or interpreter lock.
- Native OS kernel threads (
CreateThreadon Windows,sys_cloneon Linux) run concurrently across all physical CPU cores at 100% capacity. - Hardware atomic memory operations via x86_64 CPU instructions (
lock add,lock sub).
- Ultra-Compact Binary Footprint:
- Standalone executables range from 512 bytes (flat bare-metal binary) to 2.5 KB (PE64 / ELF64 / Mach-O 64).
- Absolutely zero external dependencies: no
python.exe, no MSVCRT, no libc/glibc, and no external dynamic linkers required.
- Bare-Metal Execution Speed:
- Pure x86_64 assembly performance on par with hand-tuned C and assembly.
- Fibonacci calculation ($N=40$): 0 ms.
- Sieve of Eratosthenes (100,000 prime numbers): 0 ms.
- 8 parallel threads executing 2,000,000 atomic operations: 47 ms.
- Comprehensive Cross-Platform Targets:
--target win64: Standalone Windows 64-bit PE64 Console executables (.exe).--target dll: Windows 64-bit Dynamic Link Libraries (.dll) callable instantly from Python viactypesor from C/C++.--target linux: Native Linux x86-64 ELF64 executables (.elf) using pure kernel syscalls (sys_write,sys_exit,sys_mmap,sys_nanosleep) with zero libc dependency.--target macos/--target apple: Apple macOS x86-64 Mach-O 64-bit executables (.macho) using direct Darwin BSD kernel syscalls.
- Multi-Module Single-File Compilation:
- Automatically discovers and compiles all internal modules, subpackages, and libraries in a project into a single standalone machine code binary (
.exe,.elf,.macho). - Recursively traverses local
importandfrom ... import ...statements, registers aliases, and prevents circular dependencies while strictly skipping external/virtualenv directories.
- Automatically discovers and compiles all internal modules, subpackages, and libraries in a project into a single standalone machine code binary (
- Cross-Platform Project Bundler (
pyfasm64 bundle):- Bundles complex Python applications into native standalone launcher executables for Windows (
.exe), Linux (.elf), and Apple macOS (.macho) that automatically discover virtual environments and launch in Free-Threaded (No-GIL) mode when available.
- Bundles complex Python applications into native standalone launcher executables for Windows (
Compiler Architecture
PyFASM64 is architected from the ground up as a retargetable, zero-runtime compiler with distinct frontend, semantic, and platform code-generation layers:
┌────────────────────────────┐
│ Python Source Code │
│ (Python 3.8 - 3.16t) │
└─────────────┬──────────────┘
│
▼ (Python ast parser)
┌────────────────────────────┐
│ Abstract Syntax Tree │
└─────────────┬──────────────┘
│
▼ (AstAnalyzer)
┌────────────────────────────┐
│ Semantic & Type Analysis │
│ (int, ptr, str, stack) │
└─────────────┬──────────────┘
│
▼ (Target ABI & Syscall Selector)
┌───────────────────┼───────────────────┐
▼ ▼ ▼
┌───────────────────┐ ┌───────────────────┐ ┌───────────────────┐
│ Windows PE64 │ │ Linux ELF64 │ │ Apple macOS Mach-O│
│ - Microsoft x64 │ │ - System V ABI │ │ - Darwin BSD │
│ - Shadow Space │ │ - Pure Syscalls │ │ - 0x2000000 Sys │
└─────────┬─────────┘ └─────────┬─────────┘ └─────────┬─────────┘
│ │ │
└───────────────────┼───────────────────┘
▼ (Bundled FASM Assembler)
┌───────────────────┼───────────────────┐
▼ ▼ ▼
[ Windows PE64 .exe ] [ Linux ELF64 .elf ] [ Apple Mach-O .macho ]
(~2.5 KB) (~1.8 KB) (~2.4 KB)
Platform Architecture Comparison
| Architectural Aspect | Windows x86-64 | Linux x86-64 | Apple macOS x86-64 |
|---|---|---|---|
| Binary Format | PE32+ (PE64) Console / DLL | ELF64 Executable (Type 3) | Mach-O 64 (MH_MAGIC_64) |
| Magic Header | MZ (0x5A4D) / PE\0\0 |
\x7fELF (0x464C457F) |
0xFEEDFACF (Little-Endian) |
| ABI Calling Convention | Microsoft x64 ABI | System V AMD64 ABI | System V AMD64 ABI |
| Register Parameters | RCX, RDX, R8, R9 |
RDI, RSI, RDX, RCX, R8, R9 |
RDI, RSI, RDX, RCX, R8, R9 |
| Stack Shadow Space | 32 bytes reserved by caller | None (128-byte Red Zone) | None (128-byte Red Zone) |
| Kernel Interface | Win32 API (kernel32.dll) |
Direct Linux Kernel Syscalls | Direct Darwin BSD Syscalls |
| Standard Output | GetStdHandle + WriteFile |
syscall (rax = 1 sys_write) |
syscall (rax = 0x2000004) |
| Process Termination | ExitProcess (code in RCX) |
syscall (rax = 60 sys_exit) |
syscall (rax = 0x2000001) |
| Memory Allocation | VirtualAlloc (MEM_COMMIT) |
syscall (rax = 9 sys_mmap) |
syscall (rax = 0x20000C5) |
| High-Precision Time | GetTickCount / RDTSC |
sys_nanosleep (35) / RDTSC |
sys_nanosleep (0x20000EB) / RDTSC |
| Runtime Dependencies | None (kernel32 only) | Zero libc / Zero glibc | Zero libSystem / Zero dyld |
Deep Dive: Supported OS Architectures
1. Windows x86-64 Architecture (--target win64, --target dll)
- PE64 Header Structure: PyFASM64 emits valid Portable Executable (PE32+) headers matching the Windows loader specification. The file contains
.text(executable code),.data(writable static variables and strings), and.idata(Import Directory Table forkernel32.dll). - Calling Convention: Strictly adheres to the Microsoft x64 Calling Convention. The compiler automatically provisions the required 32-byte shadow space (home space) before every API call and ensures the stack pointer (
RSP) is aligned to a 16-byte boundary prior tocallinstructions. - Shared Libraries (
--target dll): Emits proper Export Directory Tables withIMAGE_FILE_DLLcharacteristics, allowing Python modules compiled by PyFASM64 to be loaded instantly via Python's standardctypes.CDLLor linked by C/C++ applications.
2. Linux x86-64 Architecture (--target linux)
- ELF64 Executable Header: Uses FASM's native
format ELF64 executable 3targeting System V ABI without requiring external linkers (ld) or GCC. - Pure Direct Syscalls: Implements all system services through direct x86_64
syscallinstructions:sys_write(rax = 1): Outputs text directly to stdout file descriptor (rdi = 1).sys_exit(rax = 60): Terminates the process cleanly with the return code inrdi.sys_mmap(rax = 9): Dynamically allocates memory pages withPROT_READ | PROT_WRITEandMAP_PRIVATE | MAP_ANONYMOUS.sys_munmap(rax = 11): Unmaps allocated pages back to the kernel.sys_nanosleep(rax = 35): High-precision thread sleep without external libraries.
- Universal Portability: Because PyFASM64 does not link against
libc.so.6, the generated binaries run unchanged on any Linux distribution, including Alpine Linux (musl), Ubuntu, Debian, Red Hat, Arch Linux, and container base images (scratch,busybox).
3. Apple macOS x86-64 Architecture (--target macos / --target apple)
- Mach-O 64-bit Header: Emits a compliant 64-bit Mach-O binary (
MH_MAGIC_64 = 0xFEEDFACF) withCPU_TYPE_X86_64andCPU_SUBTYPE_LIB64. - Direct Kernel Load Commands: Employs
LC_SEGMENT_64(defining the__TEXTsegment and__textsection) combined withLC_UNIXTHREADto initialize the CPU state and register pointer (RIP) directly to the PyFASM64 entry point. - Darwin BSD Syscall Class: Darwin 64-bit syscalls utilize the BSD system call class mask
0x2000000:sys_write:rax = 0x2000004(rdi = 1, rsi = buffer, rdx = length).sys_exit:rax = 0x2000001(rdi = exit code).sys_mmap:rax = 0x20000C5(anonymous private memory pages).sys_nanosleep:rax = 0x20000EB(thread sleep).
- Zero dyld Overhead: Bypasses Apple's dynamic linker
dyldandlibSystem.B.dylibentirely, resulting in standalone executables that start instantaneously without security dyld-cache overhead.
Cross-Platform Project Bundler (pyfasm64 bundle)
The PyFASM64 bundler creates native standalone launcher executables that package complex Python applications for Windows, Linux, and Apple macOS:
# Bundle for Windows (generates native PE64 app.exe):
uv run pyfasm64 bundle ./my_app -o ./my_app/app.exe --target win64
# Bundle for Linux (generates native ELF64 app.elf using direct sys_execve):
uv run pyfasm64 bundle ./my_app -o ./my_app/app.elf --target linux
# Bundle for Apple macOS (generates native Mach-O app.macho using Darwin syscalls):
uv run pyfasm64 bundle ./my_app -o ./my_app/app.macho --target macos
(Note: pyfasm bundle ... can be used interchangeably)
How It Works:
- Virtual Environment Auto-Detection: Inspects the project directory for
.venv, locating local project virtual environments. - No-GIL / Free-Threaded Detection: Checks
.python-versionand system configuration; if a free-threaded Python build (3.13t-3.16t) is detected, it automatically executes with-X gil=0to unlock true multicore parallelism. - Pure Native Launcher: The launcher itself is an ultra-fast compiled binary (~350 bytes to 2.5 KB) that sets
PYTHONUNBUFFERED=1and spawns the application process with zero startup latency.
Installation
Via PyPI (Official Python Package Index)
# Using uv (recommended)
uv add pyfasm64
# Using standard pip
pip install pyfasm64
Via Conda (conda-forge organization channel)
# Using standard conda
conda install -c conda-forge pyfasm64
# Or using mamba
mamba install -c conda-forge pyfasm64
# Or using pixi
pixi add pyfasm64
Via Debian / Ubuntu PPA (eminsk/ppa)
sudo add-apt-repository ppa:eminsk/ppa
sudo apt update
sudo apt install python3-pyfasm64
(Also satisfies dependencies requiring python3-pyfasm)
Alternatively, download the latest python3-pyfasm64_*.deb from the GitHub Releases page:
sudo dpkg -i python3-pyfasm64_*.deb
From Source
git clone https://github.com/eminsk/pyfasm.git
cd pyfasm
uv sync
CLI Usage
Both pyfasm64 and pyfasm CLI commands are available and identical in syntax and options:
1. Compile and Run on Windows (PE64)
# Compile to native Windows x64 .exe and execute immediately:
uv run pyfasm64 compile examples/01_hello.py --run
# Or using the classic pyfasm alias:
uv run pyfasm compile examples/01_hello.py --run
# Compile parallel multithreading benchmark:
uv run pyfasm64 compile examples/04_multithread_parallel.py --run
2. Compile for Linux (ELF64)
# Generates native Linux x86-64 ELF executable using direct kernel syscalls:
uv run pyfasm64 compile examples/01_hello.py -o hello_linux.elf --target linux
3. Compile for Apple macOS (Mach-O 64)
# Generates native Apple macOS x86-64 Mach-O binary using Darwin BSD syscalls:
uv run pyfasm64 compile examples/01_hello.py -o hello_mac.macho --target macos
4. Compile Multi-Module Project into 1 Single Standalone Binary
# Compiles an entire multi-file project into 1 standalone binary (auto-resolves all local imports):
uv run pyfasm64 compile ./my_project -o my_app.exe
# Or compile from entry script (auto-resolves all imported helper modules):
uv run pyfasm64 compile my_project/main.py -o my_app.exe
5. Inspect Generated FASM Assembly
uv run pyfasm64 emit-asm examples/02_fibonacci.py
6. Compile to High-Performance Windows DLL
uv run pyfasm64 compile my_math.py -o my_math.dll --target dll
Supported Python Language Subset
| Feature | Syntax / API | Description |
|---|---|---|
| Functions | def name(a: int, b: int) -> int: |
Strongly-typed x86_64 functions with ABI calling conventions |
| Data Types | int, ptr, str, bool, void |
64-bit native integers, pointers, string constants, booleans |
| Arithmetic | +, -, *, //, %, &, |, ^, <<, >> |
Direct x86_64 ALU operations (add, sub, imul, idiv) |
| Control Flow | if, elif, else, while, for i in range() |
Conditional jumps, loops, break, continue, return |
| Dynamic Memory | alloc_memory(bytes), free_memory(ptr) |
OS virtual memory allocation (VirtualAlloc / sys_mmap) |
| Buffer Access | buf[i] = val and val = buf[i] |
Indexed memory read and write operations |
| Multithreading | spawn_thread(worker, param), wait_thread(h) |
Hardware OS threads running concurrently without GIL |
| Atomic Ops | atomic_add(ptr, val), atomic_sub(ptr, val) |
Thread-safe atomic operations via CPU lock prefix |
| Console I/O | print(), print_int(), print_str(), print_newline() |
Low-level buffered stdout streaming |
| Timers & Sleep | get_tick_count(), sleep_ms(ms) |
High-precision timing and thread sleep |
Benchmark Comparison
Tested on AMD / Intel x86_64 (Windows 11 & Linux 6.x):
| Benchmark | CPython 3.12 (Standard) | PyPy 3.10 (JIT) | PyFASM64 Native x64 | Speedup vs CPython |
|---|---|---|---|---|
| Fibonacci ($N=40$) | 12,450 ms | 620 ms | < 1 ms | > 12,000x |
| Sieve of Eratosthenes (100k) | 185 ms | 18 ms | < 1 ms | > 180x |
| 8-Thread Parallel Counter | 4,210 ms (GIL contention) | 1,840 ms | 47 ms (Zero-GIL) | > 89x |
| Binary Size | ~35 MB (pyinstaller) | N/A | 2.5 KB | > 14,000x smaller |
Testing & Verification
The test suite covers codegen, execution, AST parsing, multithreading, multi-module bundler, and type checking across all supported Python versions:
uv run pytest
tests/test_bundler.py ...... [ 22%]
tests/test_codegen.py ... [ 33%]
tests/test_execution.py ............. [ 81%]
tests/test_fasm_exporter.py .. [ 88%]
tests/test_multithreading.py . [ 92%]
tests/test_parser.py . [ 96%]
tests/test_types.py . [100%]
============================== 27 passed in 1.69s ==============================
Verified compatibility matrix:
- CPython 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14, 3.15, 3.16: 100% tests passing.
- Python Free-Threaded / No-GIL (3.13t, 3.14t, 3.15t, 3.16t): 100% tests passing.
- PyPy (3.8, 3.9, 3.10, 3.11, 3.12): 100% tests passing.
License
This project is licensed under the MIT License.
Metadata
Release files for pyfasm64 0.1.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyfasm64-0.1.14.tar.gz | 404.9 kB | Without provenance | Details for pyfasm64-0.1.14.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyfasm64-0.1.14-py3-none-any.whl | Python 3 | none | any | Details for pyfasm64-0.1.14-py3-none-any.whl |
Total release size: 477.4 kB
Release files / pyfasm64-0.1.14.tar.gz
| Download URL | pyfasm64-0.1.14.tar.gz |
|---|---|
| Size | 404.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec320b6456e805c88c27e598b2333c9391bfb205f6792eebbeed27d3f294e810
|
|
BLAKE2b-256 checksum How to use checksums |
cd3e5d09ffe97e2c7526f66be711cf7225363c950c433806648707a4174c9de6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / pyfasm64-0.1.14-py3-none-any.whl
| Download URL | pyfasm64-0.1.14-py3-none-any.whl |
|---|---|
| Size | 72.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f69b125bbc2e749488ac421f36edf78c3cc2d71724a90959c0ac655816ac3f1
|
|
BLAKE2b-256 checksum How to use checksums |
f2fa8c2859c0eac62f1b719fa65c13c2b403a040b0ed4a2ce28f638d867e7186
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for pyfasm64 0.1.14
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.