python_env
Introduction
The Python Environment module allows you to seamlessly integrate Python scripts into your Drupal project. It provides a service that runs Python scripts from Drupal, making it easy to leverage Python for various tasks like data processing, automation, and custom logic.
Features
- Run Python scripts directly from Drupal: Execute Python code from your Drupal site using a simple service.
- Automatic Python script folder creation: The
/python/folder is automatically created at the root of your project, where you can place your Python scripts. - JSON-based input and output: Python scripts accept and return data in JSON format, making it easy to integrate with Drupal.
- Separation of concerns: Python and Drupal logic remain separate, allowing clean code management while utilizing both platforms.
- Ideal for custom workflows: Perfect for integrating machine learning models, API interactions, or advanced data processing using Python.
Post-Installation
Once you install and enable the python_env module:
- The module automatically creates a
/python/directory at the root of your Drupal project if it doesn't already exist. - You can start adding your Python scripts to this directory.
- To run a Python script, simply call the
python_env.bridgeservice in your PHP code and provide the script name along with arguments.
No further configuration is required. You just need to place your Python scripts in the /python/ directory and use the service to execute them.
Additional Requirements
- Drupal 11+
- Python 3 installed on your server and accessible via the
python3command. - Symfony Process Component, which is included by default in Drupal Core.
Recommended modules/libraries
No additional modules or libraries are required for the core functionality of this module. However, you may want to integrate Python libraries based on your use case.
Similar projects
There are other modules for executing custom scripts or managing external integrations, but Python Environment is unique in how it integrates Python directly into Drupal, offering clean service-based architecture with structured input and output.
Supporting this Module
If you’d like to support this module, please consider contributing to the issue queue on Drupal.org or providing financial support for further development through platforms like GitHub Sponsors.
Community Documentation
For more information, please refer to the documentation and the module page on Drupal.org. Additional resources, such as video tutorials or demo sites, may be added in the future.