Python is Available in Rocket D3 10.3.1
September 11, 2019
Python is an exciting addition to the Rocket Software MultiValue databases. Following on the success of bringing Python to UniData and UniVerse, Rocket Software in now bringing Python to Rocket D3.
In Rocket D3 10.3.1 we have added Python to work with your existing data in a new language. Not only does Python allow you to move to a more modern development language, it will also help you attract a new generation to MV.
As stated in a previous blog post ‘Why Python is good for the bottom line’, “No doubt you’ve heard that Python is the fourth most popular, fastest-growing language. Not only is it easy to learn, but Python has over 138,000 (that’s now up to over 180,000) packages you can deploy to expand the functionality and efficiency of your existing MultiValue application. Initially, Python and its libraries were skewed toward developing for mathematics, science, large data, and memory management. Over time, however, the Python Package Index (PYPI) has grown to host countless standard and community-continued modules for:
- Web and Internet Development
- Database Access
- Desktop GUI
- Scientific & Numeric
- Education
- Network Programming
- Software & Game Development
D3 Python Setup
To set access to Python, update .pyconfig
1. Install the 64-bit Python version.
Usually, the appropriate source for this is https://www.python.org/.
Note that Rocket D3 can access any Python 3.X version of Python.
2. Locate the .pyconfig configuration file in the D3 installation directory.
This location should not be overwritten or changed.
3. Save the existing file to another file.
For example, .pyconfig_original.
4. Modify the .pyconfig file.
The modified .pyconfig file might look like the following:
PYHOME=C:\Program Files\Python\Python37
PYLIB=C:\Program Files\Python\Python37\python35.dll
SETTING UP XDEMO PYTHON CODE
The Rocket MultiValue databases are now being shipped with an XDEMO account that contains sample code.
To set up the Python sample code, do the following:
1. Create a directory at the OS level to hold the file.
mkdir C:\D3Python
2. Copy the items from PP to the file
:COPY PP * to :(C:\D3Python 1 Greeting.py TO Greeting.py 2 Notification.py TO Notification.py 3 AddressToCoordObj.py TO AddressToCoordObj.py 4 largenum_sqrt.py TO largenum_sqrt.py 5 DistanceBtwnPoints.py TO DistanceBtwnPoints.py [805] 5 item(s) copied
GETTING STARTED WITH PYTHON
Developers have the ability to access Python from the Rocket D3 solutions. Included in this release are:
- PYTHON – Launches the Python REPL ( Read, Eval, Print and Loop ) shell.
- RUNPY – Run a Python program from the TCL prompt.
- Calling Python from BASIC – BASIC API to access Python modules.
LAUNCHING THE PYTHON REPL FROM TCL
Using the REPL is a simple way to check access to Python, and to work with Python.
:python Python 3.7.1rc1 (v3.7.1rc1:2064bcf6ce, Sep 26 2018, 15:15:36) [MSC v.1914 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import Greeting Type your name: Mike Hello Mike >>> help(Greeting) Help on module Greeting: NAME Greeting - # Copyright (C) Rocket Software 1993-2015 DATA hello_name = 'Mike'
FILE
c:\d3python\greeting.py
RUNNING A PYTHON PROGRAM FROM TCL
Syntax: runpy filename programName.py
i.E
:runpy pp Greeting.py Type your name: Mike Hello Mike
Modules imported must be available to Python
(setting a Q pointer will allow access from TCL and Python)
:ct md d3python d3python 001 Q 002 003 c:\D3Python
FLASH BASIC API TO ACCESS PYTHON MODULES
To interact with Python from a Flash BASIC program, Rocket D3 provides several API functions:
- PyCall function
- PyCallFunction function
- PyCallMethod function
- PyGetAttr function
- PyImport function
- PySetAttr function
When using the Python API Functions, code must include:
CFUNCTION PY.BUILTIN
Any modules referenced must be defined in Python, and the BASIC code must be compiled with FlashBASIC
compile filename programname (O
There is an example program in the PBP file in the XDEMO account called LARGENUM_TEST. It calls the getsqrt function in a Python module named largenum_sqrt.py.
ModuleName = "largenum_sqrt" FuncName = "getsqrt"
* call the Python function
pyresult = %PyCallFunction(ModuleName, FuncName, NMBR)
Note that this simple program shows the extended precision that Python provides, and how it can be integrated into your MultiValue application.
:RUN PBP LARGENUM_TEST NMBR=12345678901234567894.1111111 U2 RESULT: SQRT(NMBR)= 3513641828.8201 Python RESULT: SQRT(NMBR)= 3513641828.820144253678675540738389727207403350606497150292801683