Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
90c9157
Add sample code for Nuitka standalone executable tutorial
shabnomm Aug 16, 2026
4f88fd9
Add CPU benchmark script to measure performance
shabnomm Aug 16, 2026
1f66d8e
Add sample.txt with introductory Python text
shabnomm Aug 16, 2026
98a8af3
Fix print statement formatting in wordcount.py
shabnomm Aug 16, 2026
84afcd1
Fix print statement formatting in wordcount.py
shabnomm Aug 16, 2026
6135941
Fix print statement formatting in wordcount.py
shabnomm Aug 16, 2026
41d04cb
Add newline at end of wordcount.py
shabnomm Aug 16, 2026
af39784
Fix line endings in wordcount.py
shabnomm Aug 16, 2026
ff19d96
Delete nuitka-standalone-executable/wordcount.py
shabnomm Aug 19, 2026
2a8057a
Add wordcount.py to count common words in a file
shabnomm Aug 19, 2026
ad36955
Merge branch 'master' into shabnomm-patch-1
shabnomm Aug 19, 2026
0d8f5b2
Update wordcount.py
shabnomm Aug 19, 2026
a6125f9
Fix code formatting with ruff
shabnomm Aug 19, 2026
46f9d54
Create README.md for Nuitka standalone executable
shabnomm Aug 19, 2026
a270115
Add files via upload
shabnomm Aug 28, 2026
1c19ae3
Add files via upload
shabnomm Aug 28, 2026
f7114bf
Format wordcount.py and cpu_benchmark.py with ruff
shabnomm Aug 28, 2026
1dca585
Merge branch 'master' into shabnomm-patch-1
bzaczynski Sep 13, 2026
e6741f4
Fix sample encoding and README commands
shabnomm Sep 13, 2026
431b32f
Rename Nuitka materials folder to match tutorial slug
bzaczynski Oct 15, 2026
ac8bb71
Merge branch 'master' into shabnomm-patch-1
realpython-bot Oct 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions nuitka/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Nuitka: Compile Python Into a Standalone Executable

Sample code for the Real Python tutorial on [compiling Python applications with Nuitka](https://realpython.com/nuitka/).

## Files

- `wordcount.py`: A small command-line tool that counts the most common words in a text file
- `sample.txt`: Sample text used to test `wordcount.py`
- `cpu_benchmark.py`: A CPU-bound benchmark script used to compare runtime performance across regular Python, `--mode=standalone`, and `--mode=onefile` builds

## Usage

Install Nuitka:

```console
$ python -m pip install nuitka==4.2.1
```

Compile `wordcount.py`:

```console
$ python -m nuitka --mode=standalone wordcount.py
```

Run the compiled executable against `sample.txt`:

```console
$ ./wordcount.dist/wordcount.bin sample.txt -n 5
```
30 changes: 30 additions & 0 deletions nuitka/cpu_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import time


def is_prime(number):
if number < 2:
return False

for divisor in range(2, number):
if number % divisor == 0:
return False

return True


def main():
start = time.perf_counter()

count = 0
for number in range(2, 100_000):
if is_prime(number):
count += 1

elapsed = time.perf_counter() - start

print(f"Primes found: {count}")
print(f"Time: {elapsed:.3f}s")


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions nuitka/sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Python is popular because Python is easy to learn and easy to use.
Python is also popular for data science and automation.
21 changes: 21 additions & 0 deletions nuitka/wordcount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from argparse import ArgumentParser
from collections import Counter
from pathlib import Path


def main():
parser = ArgumentParser(
description="Show the most common words in a text file."
)
parser.add_argument("file", type=Path)
parser.add_argument("-n", "--top", type=int, default=5)
args = parser.parse_args()

words = args.file.read_text(encoding="utf-8").lower().split()

for word, count in Counter(words).most_common(args.top):
print(f"{word}: {count}")


if __name__ == "__main__":
main()
Loading