October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Python Beside Delphi, Not Instead of It: How Delphi Applications Use Python

Delphi can stay the host while Python handles scripting and data-science work. Here is how Python4Delphi fits, how it differs from DelphiVCL and DelphiFMX for Python, and what to verify before shipping.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Yes. A Delphi application can stay the host and call Python for selected work such as scripting, user-editable logic, or access to Python’s data-science libraries. The main tool for that is Python4Delphi, which lets Delphi code run Python. A separate pair of projects, DelphiVCL for Python and DelphiFMX for Python, works in the opposite direction: a Python program uses Delphi GUI frameworks. These are related but different tools, and confusing them is the most common source of wrong setup decisions.

Two integration directions, three projects

The projects differ mainly by which program is in charge. In a Delphi application calling Python, Delphi owns the process. In a Python program using Delphi’s GUI, Python owns the process.

Project Which program is the host What it does GUI framework Platform scope stated
Python4Delphi Delphi application Runs Python from Delphi, gives access to Python objects, wraps Delphi objects for Python, and builds Python extension modules from Delphi classes and functions Not applicable; it is a component library Described as components for Delphi and Lazarus/FPC; the project description does not list operating systems
DelphiVCL for Python Python program Lets Python code build interfaces with Delphi VCL components VCL Windows, per Embarcadero’s January 10, 2022 release
DelphiFMX for Python Python program Lets Python code build interfaces with Delphi FireMonkey components FireMonkey Windows, Linux, macOS, and Android, per the same release and the DelphiFMX repository

If your goal is to add Python to an existing Delphi program, you need Python4Delphi. The two DelphiXXX for Python projects only matter when you are starting from Python and want a Delphi-built interface.

Why Python does not have to replace Delphi

Python’s official documentation for Python 3.13 separates two ways of combining Python with native code. The Delphi-hosted case is what the documentation calls embedding, and the Python-hosted case is extending.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“When extending, you call a C routine, when embedding, you call a Python routine.”

The same section describes the purpose of embedding: “Embedding provides your application with the ability to implement some of the functionality of your application in Python rather than C or C++.” The documentation is written for C, but the model applies to any host that can call into a Python interpreter. Source: Python 3.13 documentation, “Embedding Python in Another Application”.

Embedding: your Delphi application is the host

Your application starts, keeps its own main loop, and calls Python when it needs a routine written in Python. Typical reasons are letting users tailor behaviour with scripts, or implementing logic that is faster to write in Python than in Pascal. The documentation gives the same examples.

Extending: Python is the host

Python runs the main program and imports native modules that you build. Python4Delphi’s ability to create extension modules from Delphi classes and functions falls into this category. Use it when the Python side is the main application and Delphi code supplies specific components.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What Python4Delphi gives a Delphi developer

The project describes itself as a set of free components that wrap Python for Delphi and Lazarus/FPC. Its project page lists four main capabilities. Source: Python4Delphi project.

Running Python code from Delphi

The project provides low-level access to the Python API and supports bidirectional interaction between Python and Delphi. This is the entry point for scripting: Delphi loads Python code, runs it, and reads results back.

Working with Python objects

Python objects are accessed through Delphi custom variants. Code can read and call Python values from Delphi using ordinary Delphi syntax rather than raw API calls, which keeps application code easier to read.

Exposing Delphi objects to Python

Delphi objects can be wrapped for Python through RTTI, so a script can work with objects the application already owns. Limit exposure deliberately: anything a script can reach is part of the security and stability surface of your application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Building Python extension modules in Delphi

Delphi classes and functions can be compiled into Python extension modules. This is the extending direction described above, and it is the route to take when Python needs Delphi-written functionality without Delphi hosting the process.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Setting up a Delphi application to run Python

The steps below follow the installation guidance for Python4Delphi. Exact menu locations vary between RAD Studio versions, so check the wording against your IDE.

  1. Get Python4Delphi from the Python4Delphi repository and choose the revision that matches the Delphi version you use.
  2. Add the Python4Delphi source folders to the Delphi IDE library path. The installation guidance covers this step: Python4Delphi installation guidance. In recent RAD Studio releases this setting is under Tools > Options > Language > Delphi > Library.
  3. Install a Python release and confirm it is within the range your Python4Delphi revision supports. Your application will load that runtime at run time, so the Python version on the machine that runs the program matters as much as the one on your development machine.
  4. Optionally, use Embarcadero’s PythonEnvironments project to manage design-time embedding of Python environments. Its repository describes Python 3.8 through 3.13 compatibility, so confirm that range for the revision you install: PythonEnvironments repository.
  5. Build a small test that runs one Python statement from Delphi and returns a value. Only add larger scripts after this works on the target machine.

Choosing the right approach

  • Use Python4Delphi when a Delphi application already exists and needs scripting, Python libraries, or Python-written logic inside it.
  • Use Python4Delphi’s extension-module capability when Python is the main program and needs Delphi-written functions or classes.
  • Use DelphiVCL for Python when Python code must produce a native Windows interface built on VCL.
  • Use DelphiFMX for Python when the interface must run on Windows, Linux, macOS, or Android, subject to the verification steps below.
  • Do not choose any of these to replace a Delphi application wholesale; the design target is a shared process with clear boundaries.

Versions and platforms to verify before you ship

The platform and version statements in this article come from project descriptions and a January 10, 2022 Embarcadero release. Repositories change, so check the following before a production deployment:

  • The current platform list for DelphiFMX for Python in its repository, since the release is more than four years old.
  • The Python version range for your exact Python4Delphi and PythonEnvironments revisions.
  • The package-installation steps and the Python runtime your application will ship with.
  • Deployment licensing for the Delphi, Python4Delphi, and any bundled Python components you use.

Embarcadero lists its Python tools at Embarcadero’s Python tools page, which is the best starting point for current product information.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.