What can the popular and ubiquitous, open source language Python have to offer Xojo developers? Let's take a look.
How often in the history of programming languages has any been declared to be the-only-one-you-need-to-learn, especially for work? For some, that has proven to be somewhat true. There are still living programmers that are nursing along ancient and upgraded computers running COBOL built solutions as IBM developer Adam DeMarino explains on the IBM blog back in 2020. But you aren't going to find the new hotness in COBOL. Python isn't new, having its roots in the 1980s (more specifically, 1989) and, while it never became the-only-one-you-need-to-learn, it has found its place, or places. Even IBM, our COBOL king, has nice things to say about it. Less the hero of the story, but rather, the best companion of heroes. And those places can be quite attractive to Xojo developers.
- Python is found wrapping the new hotness, or enabling the new hotness, such as NumPy, available under a form of BSD license.
- Python is also used extensively in some vertical industries as a scripting language. For example, in the professional 3D and special effects market, many of the most advanced tools (such as Maya) utilize Python as a scripting language. There is even a complete Python module version of Blender.
For Xojo developers, the ability to work with or leverage Python expands what you can accomplish. Some of the developers of the solutions included with Omegabundle for Xojo support Python. During Python Week (July 29, 2024-August 2, 2024), we introduce you to five of them. Come back to this story here for an introduction and links to each of them.
Scripting Valentina Reports for Xojo with Python
Valentina Reports now can use the power of Python for flexible report generation.
Valentina Release 14 introduced a unified scripting model which included Valentina Reports for Xojo. Here’s how you can use Python in your reports:
- Source Queries. Create dynamic and complex data sources for your reports using Python. You can write custom queries to retrieve data directly, tailored to your specific needs.
- Expressions. Enhance your reports with dynamic calculations and data manipulation. Python expressions can be embedded within the report itself, enabling you to perform calculations, format data, or even conditionally display elements based on specific criteria.
- Scripted Report Generation Stages. Valentina Reports allows you to execute custom Python scripts at different stages of the report generation process. This grants you fine-grained control over the report creation flow. You can use Python scripts to pre-process data, manipulate layout, or even generate dynamic content based on report data.
Python3Script Plugin for Xojo
Einhugur Plugin Pack for Xojo includes Python3Script plugin, a Xojo plugin that adds a Python interpreter to Xojo applications. You can even create classes from Xojo code. The Einhugur approach is to work with the version of Python installed on the same computer running your application, with flexibility in which version of Python you work with.
Not only can your solution utilize Python modules and libraries, but it also enables functions to allow Python script to manipulate your Xojo objects.
Read more about Python3Script plugin for Xojo and how it can extend your app using Python.
Stored Routines in Python on Valentina Server
Centralize your business logic using stored procedures on Valentina Server. Valentina Server 14 introduced a completely new Python implementation that supports using Python as a native language for Stored Routines: Stored Procedures and User Defined Functions. Now make use of over 160 standard Python modules as well as third party and custom Python modules.
Why Stored Routines Anyway?
Stored routines are stored in the database, reducing network traffic between Valentina CLIENT and Valentina Server. Build cursors, iterate records and calculate value(s) entirely on the server. If you use Valentina CLIENT, you can make calls individually to Valentina Server, when you load the next record of a cursor. The network itself can be the primary bottleneck of client-server applications. If you use stored procedures instead, then you get almost no network traffic for this calculation and get back only the result.
MBS Xojo Python Plugin
The MBS Plugin Complete Release 24.3 introduced another way to work with Python: the MBS Xojo Python Plugin, and the new PythonMBS class. This allows you to evaluate Python code in Xojo and run scripts and more.
- Use Python code within your Xojo application.
- Load a python 3.x library from a given path. You need to bring the python folder or install python via official installer or package manager.
- Import existing Python modules
- Register custom functions to call to Xojo code from Python
- Converts data types between Xojo and Python including arrays and dictionaries.
- Evaluate Python expressions
- Redirect print() function in Python to Xojo event to capture console output.
- Report problems in Python with Xojo exceptions.
- Run existing Python scripts in the context of your applications.
- Query and set variables in Python in your Xojo code.
- Use multiple Python environments with local variables simultaneously.
Read more about what you can accomplish using MBS Xojo Python Plugin.
Unified Python Scripting in Valentina Studio PRO
With Valentina Release 14, Paradigma Software introduced unified JavaScript and Python engines in Valentina Reports, ValentinaDB Stored Procedures and Valentina Forms. Previously, different products used different engines which lead to some inconsistencies in how scripts were executed. Now, with a unified engine, the behavior is consistent and reliable across all parts.
The Python engine is now integrated with various aspects of Valentina Studio, including Forms and Scripts, Valentina Reports, and even the ValentinaDB engine itself. This enables a more powerful development experience by allowing you to leverage Python for various tasks.
Valentina Studio offers comprehensive Python integration for your scripts, including module support for:
- built-in modules
- third-party modules
- custom modules
Valentina Studio's Python integration expands its capabilities by allowing you to utilize modules installed within virtual environments (venv). These isolated environments, created using tools like venv, keep project-specific dependencies separate from the system-wide Python installation.