Please see answer by @librebel & @wertie in this post → best macro to detect the operating system
If you do a search on this forum you will see numerous postings for Python.
Here are some relevant links (not all from this forum):
Missing Python in LibreOffice organize macros menu
Transfer from Basic to Python
Basically python scripts reside in system, user or document storage. To embed a script in document see the EmbedPythonScriptInDocument.odt file in my answer here → Can I embed python script and integrate with basic?
Interaction → Christopher Bourez’s blog
More here → Information and resources for LibreOffice macros
Well, that’s just some of it. There is a bunch more on the subject but that should easily get you started. Much more than I had. Found all this & more on my own when starting python & LO a couple of years ago.
Used seperate disk sitting around with almost nothing done to it after a Ubuntu 17.04 Mate install. Removed all traces of LibreOffice. Had LO 22.214.171.124 around (this is from TDF) and installed. Immediately after install ( nothing else done), the following were present:
Script provider for BeanShell extension for LibreOffice 5.4 .5.1
Script provider for Python for LibreOffice 5.4 .5.1
Was now able to:
Tools->Macros->Run Macro... & from LibreOffice Macros successfully run
pythonSamples->TableSample->createTable both Python.
install LO extension I wrote, completely in python, for Calc. Executes from Toolbar. Ran without problem including various functions within dialog.
Inserted a pushbutton on Calc sheet. Connected
Execute action event to various python scripts in
MyMacros and all ran without a problem
Works for me.
If this answers your question please tick the (upper left area of answer). It helps others to know there was an accepted answer.