Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

Python4Delphi

English · Русский

Overview

Current home: https://github.com/pyscripter/python4delphi

From that page:

Python for Delphi (P4D) is a set of free components that wrap up the Python dll into Delphi and Lazarus (FPC). They let you easily execute Python scripts, create new Python modules and new Python types. You can create Python extensions as dlls and much more. P4D provides different levels of functionality:

  • Low-level access to the python API
  • High-level bi-directional interaction with Python
  • Access to Python objects using Delphi custom variants (VarPyth.pas)
  • Wrapping of Delphi objects for use in python scripts using RTTI (WrapDelphi.pas)

P4D makes it very easy to use python as a scripting language for Delphi applications. It comes with an extensive range of demos and tutorials.

The commit log indicates development is active as of Sep 2024. Lazarus lpk files and demos exist.

Lazarus port

Lazarus port: Using Python in Lazarus on Windows/Linux

See also

FreeBSD

I was able to get this working on FreeBSD without relying on Lazarus design-time components:

pascal
program simplefpcdemo;
    uses PythonEngine, dynlibs;
    
    var eng : TPythonEngine;
    begin
      eng := TPythonEngine.Create(Nil);
      eng.LoadDll;
      if eng.IsHandleValid then
        begin
          WriteLn(' evens: ', eng.EvalStringAsStr('[x*2 for x in range(10)]'));
          eng.ExecString('print "powers:", [x**2 for x in range(10)]');
        end
      else writeln('invalid library handle!', dynlibs.GetLoadErrorStr);
    end.

The output:

pascal
evens: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
       powers: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

My personal working copy (including a Python wrapper for my terminal library) is https://github.com/tangentstorm/py4d .


From the Free Pascal wiki, page "Python4Delphi", as the Internet Archive kept it on 2025-06-05, last changed on 2024-09-19. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .