Hello,
Please see answer by @librebel & @karolus in this post → best macro to detect the operating system
Edit 2018-05-19:
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.
Edit 2018-05-20:
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 5.4.5.1 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 JavaScript extension for LibreOffice 5.4 .5.1
Script provider for Python for LibreOffice 5.4 .5.1
Was now able to:
- 
From menu Tools->Macros->Run Macro...  & from LibreOffice Macros successfully run HelloWorldPython & 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.