Connectivity in Maple 2023
|
OpenMaple for Python
|
|
•
|
The new OpenMaple for Python is an interface for the Python programming language that allows you to access Maple algorithms and data structures from a Python session on the same machine.
|
•
|
You can use OpenMaple for Python from any Python session or within Maple from a Python Code Edit Region.
|
|
Using Maple commands and symbols in Python
|
|
There are two ways to make use of Maple commands and symbols in the OpenMaple API: using maple.symbols or maple.namespace.
•
|
maple.symbols lets you specify a list of symbols as a string. You can then assign these to Python variables and use them freely.
|
•
|
maple.namespace lets you reference any symbol from Maple with a simple prefix.
|
|
|
Conversions
|
|
OpenMaple for Python can perform automatic conversions when Python objects are used as input to Maple, allowing results computed using
Python type
|
Maple type
|
dict
|
table
|
list
|
list
|
set, frozenset
|
set
|
Fractions.fraction
|
fraction
|
sympy.Basic
|
anything
|
|
|
|
|
Python commandline flag
|
|
The Maple commandline script on macOS and Linux now accepts an additional flag, -python, which launches the version of Python distributed with Maple. This is automatically configured to enable OpenMaple for Python to work.
To use it simply type maple -python in a terminal window and then enter import maple to load OpenMaple for Python.
|
|
|
Python Code Edit Regions
|
|
•
|
Code Edit Regions now also include Python as a supported language. Simply insert a Code Edit Region into a worksheet and from the Code Edit Region properties in the Context Panel, for Language select Python. The result is a Code Edit Region which behaves identically to a Maple Code Edit Region but uses Python syntax highlighting.
|
•
|
When this region is executed, the underlying Python session associated with the Python package will be used. To access any of the variable state from this Python session, use the Python package:
|
>
|
|
| (2.1) |
| (2.2) |
|
|
Code Generation for RESTful APIs
|
|
The new OpenAPI package provides a way to automatically create Maple packages to interface with RESTful APIs from an OpenAPI specification. OpenAPI (formerly Swagger) is a standard for describing RESTful APIs with a JSON or YAML file. An example specification is provided in the examples folder to interface with the RESTful API test site at https://jsonplaceholder.typicode.com. Passing that specification to OpenAPI:-GenerateModule will create a source file for a Maple package that can be read into Maple and used to access the JSON Placeholder HTTP API.
>
|
filename := cat( kernelopts(datadir), kernelopts(dirsep),
"example", kernelopts(dirsep), "PlaceHolder.yaml"):
|
>
|
output := OpenAPI:-GenerateModule( filename );
|
Wrote 69460 characters to PlaceHolder.mpl
| |
| (3.1) |
| (3.2) |
| (3.3) |
>
|
PlaceHolder:-getPost(1, 'nopopup');
|
| (3.4) |
|
|