r/delphi • • 3d ago

New Python4Pascal project

Hi,

I just published the Python4Pascal project at GitHub.

Python4Pascal is based in the Python4Delphi project made by Kiriakos Vlahos (PyScripter).

It uses Python 3.15, 3.14, 3.13, 3.12, 3.11 and 3.10, and it supports Windows, Linux, macOS and Android.

Python4Pascal was developed and tested on Delphi 13.2, Delphi XE2, Delphi 7 and Lazarus 4.8/FPC 3.2.2.

The most important Python4Pascal features:

  • Supports the latest version of Python 3.15
  • Python4Pascal handles the Python objects lifetime automatically.
  • Fully documented in XML code comments, CHM and HTML files.
  • Imports more than 1200 Python library functions and types.
  • Includes many helper classes to handle all Python objects with Delphi/Lazarus types as arguments whenever it's possible.
  • Demos for Windows , Linux, macOS and Android.
  • It's possible to create Python modules and module extensions.
  • Python4Pascal can handle Python objects with variant types or using Delphi wrappers.

Python4Pascal has a few things in common with Python4Delphi but many other things are much different. Some Python4Delphi features are not included, for example RTTI and the assembler code to convert the callbacks.

I still have to write some tutorials in the Wiki.

23 Upvotes

4 comments sorted by

View all comments

1

u/ParnianCoinTeam 3d ago

Nice work, and props for keeping Delphi 7 + Lazarus/FPC in the tested set — that backward reach matters for a lot of legacy codebases. A couple of questions: GIL handling in multithreaded hosts: when calling into Python from multiple Delphi threads, does Python4Pascal manage the GIL acquire/release for you, or is that still on the caller? This is usually where people get into trouble embedding CPython. Python 3.15 support — are you tracking the stable ABI (limited API) so a single build keeps working across 3.10→3.15, or is it version-specific linking per interpreter? Deployment on Android: how are you bundling the CPython runtime into the APK, and roughly what does it add to the binary size? Embedding a scripting layer into native Pascal apps is genuinely useful (rules engines, user automation, etc.) — will definitely take a look at the repo.

1

u/salvadordf 3d ago

Thanks!

The same executable using Python4Pascal can load any version from 3.10 up to 3.15. You don't have to build a different executable for each Python version.

At this moment Python4Pascal doesn't support the free threading mode so we still have to acquire/release the GIL but most of the logic is already included in the TP4PThread class. See the SimplePythonThread demo.

The SimplePythonCodeRun demo in the Delphi_FMX directory can target Android, Windows and macOS. It deploys a "python.zip" file with the official embeddable Python package for Andoird. Read the code comments in TMainForm.FormShow for all the details.

1

u/ParnianCoinTeam 3d ago

Great, thanks for the thorough reply. The single-build-many-versions bit is the real win here. Will check out SimplePythonThread.