Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

pocketpy

> 编程语言
Open source

Portable Python 3.x Interpreter in Modern C for Game Scripting

2.1K stars0 likes0 views
WebsiteGitHub

About

Portable Python 3.x Interpreter in Modern C for Game Scripting

pocketpy: portable python 3.x interpreter

pocketpy is a portable Python 3.x interpreter, written in C11. It aims to be an alternative to Lua for game scripting, with elegant syntax, powerful features and competitive performance. pocketpy has no dependencies other than the C standard library, which can be easily integrated into your C/C++ project. Developers are able to write Python bindings via C-API or pybind11 compatible interfaces.

Please see https://pocketpy.dev for details and try the following resources.

  • Live Python Demo: Run Python code in your browser
  • Live C Examples: Explore C-APIs in your browser
  • Godot Extension: Use pocketpy in Godot Engine
  • VSCode Extension: Debug and profile pocketpy scripts in VSCode
  • Flutter Plugin: Use pocketpy in Flutter apps
  • Raylib Bindings: Use raylib with pocketpy

Supported Platforms

pkpy should work on any platform with a C11 compiler. These platforms are officially tested.

  • Windows 64-bit
  • Linux 64-bit / 32-bit
  • macOS 64-bit
  • Android 64-bit / 32-bit
  • iOS 64-bit
  • Emscripten 32-bit
  • Raspberry Pi OS 64-bit
  • Luckfox Pico SDK 32-bit

On Windows platform, only MSVC compiler is officially supported.

Quick Start

You have two options to integrate pkpy into your project.

Use CMake (Recommended)

Clone the whole repository as a submodule into your project, In your CMakelists.txt, add the following lines:

cmake
add_subdirectory(pocketpy)
target_link_libraries(<your_target> pocketpy)

See CMakeLists.txt for details.

It is safe to use main branch in production if CI badge is green.

Use the single header file

Download the pocketpy.h and pocketpy.c on our GitHub Release page. And #include it in your project.

Compile Flags

To compile it with your project, these flags must be set:

  • --std=c11 flag must be set
  • For MSVC, /utf-8 and /experimental:c11atomics flag must be set
  • NDEBUG macro should be defined for release build, or you will get poor performance

For amalgamated build, run python amalgamate.py to generate pocketpy.c and pocketpy.h in amalgamated/ directory.

Example

…

Features

Name Example Supported
If Else if..else..elif ✅
Loop for/while/break/continue ✅
Function def f(x,*args,y=1): ✅
Subclass class A(B): ✅
List [1, 2, 'a'] ✅
ListComp [i for i in range(5)] ✅
Slice a[1:2], a[:2], a[1:] ✅
Tuple (1, 2, 'a') ✅
Dict {'a': 1, 'b': 2} ✅
F-String f'value is {x}' ✅
Unpacking a, b = 1, 2 ✅
Star Unpacking a, *b = [1, 2, 3] ✅
Exception raise/try..except.. ✅
Dynamic Code eval()/exec() ✅
Reflection hasattr()/getattr()/setattr() ✅
Import import/from..import ✅
Context Block with <expr> as <id>: ✅
Type Annotation def f(a:int, b:float=1) ✅
Generator yield i ✅
Decorator @cache ✅
Match Case match code: case 200: ✅

Performance

Currently, pkpy is as fast as cpython 3.9. Performance results for cpython 3.9 are applicable to for pkpy.

See https://pocketpy.dev/performance/ for details.

And these are the results of the primes benchmark on Intel i5-12400F, WSL (Ubuntu 20.04 LTS), which roughly reflects the performance among c++, lua, pkpy and cpython.

name version time file
c++ gnu++11 0.104s ■□□□□□□□□□□□□□□□ benchmarks/primes.cpp
lua 5.3.3 1.576s ■■■■■■■■■□□□□□□□ benchmarks/primes.lua
pkpy 1.2.7 2.385s ■■■■■■■■■■■■■□□□ benchmarks/primes.py
cpython 3.8.10 2.871s ■■■■■■■■■■■■■■■■ benchmarks/primes.py

Used By

Description
Tesselmax.EM Distributed electromagnetic field simulator for silicon photonics and RF/interconnect design.
godot-pocketpy Godot extension for using pocketpy in Godot Engine.
TIC-80 TIC-80 is a fantasy computer for making, playing and sharing tiny games.
py-js Python3 externals for Max / MSP.
crescent Crescent is a cross-platform 2D fighting and beat-em-up game engine.
orxpy Python extension for orx engine.
CANopenTerm Open-source software tool for CANopen CC networks and devices.

Submit a pull request to add your project here.

Contribution

All kinds of contributions are welcome. Please read CONTRIBUTING.md for development setup, build, testing, and PR guidance.

  • Submit a Pull Request
    • fix a bug
    • add a new feature
  • Open an Issue
    • any suggestions
    • any questions

If you find pkpy useful, consider star this repository.

Sponsor this project

You can sponsor this project via these ways.

  • Github Sponsors
  • Buy me a coffee

Your sponsorship will help us develop pkpy continuously.

Premium supporter

Special thanks to our premium supporter, Tesselmax, for sponsoring the development of pocketpy.

Tesselmax builds Tesselmax.EM, a distributed electromagnetic field simulator for silicon photonics and RF/interconnect design (FDTD, FDFD, and mode solving across GPU clusters). Tesselmax embeds pocketpy as the scripting engine in our simulation console, so user scripts drive geometry, materials, sources, and post-processing.

Website: https://fdtd.io

Reference

  • cpython

    The official implementation of Python programming language.

  • byterun

    An excellent learning material. It illustrates how Python's virtual machine works.

Star History

License

MIT License

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ccc11header-onlyinterpreter

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言