Python
Divooka Compute ships SteelPython, Methodox's Python 3.12, as spy.exe in its folder. In it, Divooka's packages, workloads and documents import like any Python module: no import clr, no AddReference, and no Python installed on the machine. SteelPython runs on .NET itself, so a package's types are Python classes and a document's graphs are Python functions.
import Divooka.Workloads.AudioProcessing as audio # a package
import Statistics # Statistics.dvk, beside this script
import divooka
tone = audio.AudioGenerators.Tone(440, 0.5) # a node is a function of its type
print(audio.AudioAnalysis.Duration(tone)) # 0.5
print(Statistics.Mean([3, 4, 8])) # a Function graph of the document
Statistics.Run() # its entry graph, run whole
Starting it
- In the editor: open the dock's Terminal tab with
Ctrl+Shift+`, press + and choose SteelPython. A Python prompt starts in the workspace folder holding the document on screen;exit()ends it. See The window. - From any terminal session, whatever its shell, and from any command line in Divooka Compute's folder,
spyanswers by name - it is SteelPython's own command line, with Divooka's imports added:
| To | Write |
|---|---|
| Run a script | spy script.py |
| Run a line | spy -c "print(1 + 1)" |
| Run a module | spy -m module |
| Type Python and see each answer | spy |
help(divooka) at the prompt lists what can be imported and how.
Import names
| To get | Write | For example |
|---|---|---|
| A package | import its name as the distribution states it |
import Divooka.Workloads.AudioProcessing as audio |
| A package, by the name Divooka Compute shows it under | divooka.package(name) |
divooka.package("Audio Processing") |
| A workload: every package it names | divooka.workload(id or name) |
divooka.workload("audio-processing") |
| A document beside your script | import its file name |
import Statistics for Statistics.dvk |
| A document anywhere | divooka.document(path) |
divooka.document("Examples/Basics/Hello World.dvk") |
| What this distribution ships | divooka.packages(), divooka.workloads() |
Names you import are exact, as Python's always are: Divooka.Workloads.AudioProcessing, not divooka.workloads.audioprocessing, and import Statistics does not find statistics.dvk. divooka.package and divooka.workload take a name the way Pure's Import(...) does: an assembly name, an id or a shown name, in any case.
Packages
A package's module holds the types its nodes are methods of, and the types those nodes take and return: from Divooka.Workloads.AudioProcessing import AudioGenerators, Waveform. A node is a function of its type - AudioGenerators.Tone(440, 1) is the node Tone - because two types of one package may each have a node of the same name, and the type keeps them apart.
- Arguments convert as they do for any .NET method: numbers, text,
TrueandFalse, lists for arrays and lists, dictionaries for dictionaries, and keyword arguments by the parameter's name. A node's result is the object the node returns, which you pass on to the next node, or read through its members. - The words a package name begins with -
Divooka,Divooka.Workloads- are modules too, soimport Divookaand thenDivooka.Workloads.AudioProcessing.AudioGeneratorsworks. - The first package you import takes a few seconds, while the distribution's packages load; every import after it is immediate.
Workloads
divooka.workload("audio-processing") - or "Audio Processing" - gives one module holding every name of every package the workload names, with the package modules themselves in __packages__. A workload is the starting set of packages a document made from it references, and this is the same set.
Documents
A document is a module whose functions are its graphs: one for each Function, Routine and Constructs graph it holds, named as Divooka Compute names it, taking the graph's inputs in order and by name, with the defaults the graph declares. Run(*arguments) runs the document's entry graph as running the document does.
import divooka
hello = divooka.document("Examples/Basics/Hello World.dvk")
hello.Run()
help(hello) # its graphs and what they take
- By name,
import Statisticslooks forStatistics.dvk, thenStatistics.dvj, in the foldersimportsearches - your script's folder first - so a script and its documents travel together. A document whose file name has a space in it is imported withdivooka.document. - By path,
divooka.document(path)looks beside your script, then in the working folder, then in Divooka Compute's folder;.dvkor.dvjis added to a name with none. Asking twice gives the same module. - A module of your own wins:
Statistics.pybesideStatistics.dvkis whatimport Statisticsgives you. - Changed the document?
importlib.reload(Statistics), ordivooka.reload(module)for onedivooka.documentgave you, reads it again. - The first import of a document builds its program, which takes a moment; calls after that are quick.
- What a document prints goes to the console, after anything your script printed before the call.
In the editor
This section grows as Python reaches Divooka Compute's own window.
Coming from pythonnet
Nothing here needs import clr, clr.AddReference or a CPython installation, and nothing is copied between two runtimes: a Divooka object in Python is the object itself. import clr still works for code written against pythonnet, but Divooka's names never need it.
See also
- Divooka SDK - building on Divooka from code: the libraries, the command-line tools and the ways in.
- Pure - Divooka's C# scripting, which imports packages and documents the same way.