Hi gang!
Editorial
Fun fact: I've been using FreeBSD for quite a while now and to be perfectly honest with you lot I'm (still) quite passionate about the whole thing. Always have, always will be. At the time of writing my backup VPS server is ("was") building 15.0-RELEASE (source hosted on my main server for security reasons). And speaking of said main server... well, today I've reached a personal milestone: Java no longer really exists on my server(s). No more JDK ("sorta"), no more (home brewed) Java programs ("class files") which perform certain maintenance functions, no more 'weird' folder structures to support a (somewhat) limited design for packages.
SO => 'Duke'
has been (officially) replaced by (a) Python
, surely a much better companion for a daemon? 
Anyway, I've had the intention to look deeper into Python for quite a few years, and last year... it actually happened! The more I learned the more excited I became and well, here we are. Time for some advocating!
Interpreted language
(and in my opinion also more accessible than lang/perl...)
Python, just like Perl (and any other shell) isn't just a programming language, but also an interpreter. Meaning? Well...
As you can see: this means that you can easily start it, after which you get onto a new command line from which you can do "Python stuff".
But that's not what makes this feature so interesting: this also means that you can easily add a shebang to your scripts (you know, something like: #!/usr/local/bin/python?), set the execution bit (
However, don't be fooled by this simple looking example... even though Python can be awesome for coding scripts it's still a full fledged OOP environment as well. So, you can easily utilize broader logic by using classes and the likes.
Re-using code is very easy (and logical!)
Let's say I coded a script called getStats.py. It has a function called "usersOnlineNow()" which doesn't only list all currently online users, it also recognizes aliases of my closest friends and actively filters on them. So this might be something I want to re-use in some of my other scripts. When dealing with Java you're now getting into the territory of (virtual) packages which can become annoying to use because they rely on specific folder structures which represent the whole package (and its domain). For example: lan/intranet/getStats.java.
With Python otoh you can easily do this: import getStats, right from within the same folder where the original script resides. Or maybe: from getStats import usersOnlineNow, this would only make the function 'usersOnlineNow()' available in my new script; so everything else in getStats would be ignored.
And if you want to create (virtual) packages to combine several of your modules? Also easy: just create a new folder, optionally add a file called __init__.py to provide some documentation (and maybe some optional initialization routine(s)). Then add your modules (so: "the scripts which contain functions that you plan to re-use in other scripts"), and done! Now you can simply 'import' the folder name, or import individual modules or, as shown earlier, individual functions.
Documenting your code is really easy
In my opinion it's good practice to comment your code and/or shell scripts. Unfortunately many programming languages rely on other tools to take full advantage of such documentation. For example an IDE which can show you what a certain function or class is supposed to do. Well... Python supports this right out of the box, while also providing a nice tool which allows you to take more advantage of it.
First things first... Python has its own help system (!) which might not be a full substitute for reference documentation, but it can still be quite useful:
However, this also leads to the question: where does this documentation come from? If you ask help about, say, the print() function then how does it get all that information? Well, from so called docstrings. A docstring is a line which is surrounded by three double quotes: """This is an example of a docstring in Python.""".
So here's where things get more interesting: if you provide such a docstring below any kind of definition then you'll automatically document whatever object you just defined. So... whenever you create (or define) a new function, (global) variable, class or a method: one docstring is all you need to provide documentation. And the best part? You can either use oneliners, or write out a small summary, there are no strict rules here.
And all those docstrings can then be automatically used by Python. Either within its help system (as shown above), or when using the pydoc utility: this can parse any Python script and print (or save) a summary, either in text or HTML format. Oh, and that pydoc utility? It's actually a Python script of its own
Of course there are many more (awesome) reasons to start using Python (like being able to run a debugger straight from the command line!), but these are simply my personal favorites.
Which then begs the question: "What version should you pick?". When in doubt then I'd stick with the default, however... it might be useful to start by checking the active Python releases. Right now 3.12 seems like a more logical choice to me, also considering that it'll be supported for another 2 years. Or, if you want to go a little more "bleeding edge" but without the actual risks then 3.13 is also a solid choice.
Once you have this out of the way then it's time to install your pick. In addition I also suggest installing lang/python-doc-text and/or lang/python-doc-html because not only does this provide some solid information, it also includes the official Python tutorial which, in my opinion anyway, can be an awesome help & reference. Fun fact: this tutorial also seriously helped me out to get started with Python.
Oh, and of course you can also install binary packages if you'd like:
When you install some of these libraries then they become available system-wide: so, accessible for all your scripts. Usually this isn't much of a problem, but what if you need a specific version of a library, or maybe another variant? Or what if... some names overlap?
PIP
In case you're wondering: Pip Installs Packages
Python has its own package manager called PIP, and as you might have guessed: it's even written in Python itself. And PIP can also be used to install packages like the ones I mentioned above. By default PIP is only accessible on FreeBSD once you set up a so called virtual environment:
So what is happening here... by using the venv module I told Python to set up a so called virtual environment: this is a separated environment with its own Python interpreter and its own Python libraries (or "modules"). And because it's separated you can install (and use) whatever library you want and without the risk of possibly disrupting other projects. For example... there are many good libraries available for cryptography, but I've become quite keen of pycryptodome:
PyPi working its magic here 
So now I have access to all the features of pycryptodome, but only within this virtual environment, and also only when it's activated (noticed the change in my prompt btw?):
See what I mean?
And now?
Well, if you followed my tutorial up to this point then you should have everything installed to start using Python. And the best way to learn... is to actually start using it. So... why not build yourself a Python script (remember the shebang!) and then try to make it "do" something? Seriously, the best way to learn a programming language is to simply start using it.
And there you have it!
Thanks for reading, I hope you guys found this useful.
Editorial
Fun fact: I've been using FreeBSD for quite a while now and to be perfectly honest with you lot I'm (still) quite passionate about the whole thing. Always have, always will be. At the time of writing my backup VPS server is ("was") building 15.0-RELEASE (source hosted on my main server for security reasons). And speaking of said main server... well, today I've reached a personal milestone: Java no longer really exists on my server(s). No more JDK ("sorta"), no more (home brewed) Java programs ("class files") which perform certain maintenance functions, no more 'weird' folder structures to support a (somewhat) limited design for packages.
SO => 'Duke'
Anyway, I've had the intention to look deeper into Python for quite a few years, and last year... it actually happened! The more I learned the more excited I became and well, here we are. Time for some advocating!
So why Python?
Just so we're clear? => I'm not a professional developer, just a hobby (Java) programmer who learned Python and got quite passionate about it. In addition I'm also quite familiar with shell scripting (obviously), VBA, C# and ASP.NET.Interpreted language
(and in my opinion also more accessible than lang/perl...)
Python, just like Perl (and any other shell) isn't just a programming language, but also an interpreter. Meaning? Well...
Code:
peter@zefiris:/home/peter/temp $ python
Python 3.13.13 (main, Apr 11 2026, 21:11:22) [Clang 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd7080 on freebsd14
Type "help", "copyright", "credits" or "license" for more information.
>>> name = "ShelLuser"
>>> print(len(name))
9
>>> print(type(name))
<class 'str'>
>>> print(name)
ShelLuser
>>> dir(name)
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix', 'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>>
As you can see: this means that you can easily start it, after which you get onto a new command line from which you can do "Python stuff".
But that's not what makes this feature so interesting: this also means that you can easily add a shebang to your scripts (you know, something like: #!/usr/local/bin/python?), set the execution bit (
chmod +x myscript.py) and then you can just run 'm from your shell as if it were a 'real' program. Which obviously makes it a lot more usable and accessible for automating administrative processes rather than having to manually start runtime all the time (which you normally always need to do with Java).However, don't be fooled by this simple looking example... even though Python can be awesome for coding scripts it's still a full fledged OOP environment as well. So, you can easily utilize broader logic by using classes and the likes.
Re-using code is very easy (and logical!)
Let's say I coded a script called getStats.py. It has a function called "usersOnlineNow()" which doesn't only list all currently online users, it also recognizes aliases of my closest friends and actively filters on them. So this might be something I want to re-use in some of my other scripts. When dealing with Java you're now getting into the territory of (virtual) packages which can become annoying to use because they rely on specific folder structures which represent the whole package (and its domain). For example: lan/intranet/getStats.java.
With Python otoh you can easily do this: import getStats, right from within the same folder where the original script resides. Or maybe: from getStats import usersOnlineNow, this would only make the function 'usersOnlineNow()' available in my new script; so everything else in getStats would be ignored.
And if you want to create (virtual) packages to combine several of your modules? Also easy: just create a new folder, optionally add a file called __init__.py to provide some documentation (and maybe some optional initialization routine(s)). Then add your modules (so: "the scripts which contain functions that you plan to re-use in other scripts"), and done! Now you can simply 'import' the folder name, or import individual modules or, as shown earlier, individual functions.
Documenting your code is really easy
In my opinion it's good practice to comment your code and/or shell scripts. Unfortunately many programming languages rely on other tools to take full advantage of such documentation. For example an IDE which can show you what a certain function or class is supposed to do. Well... Python supports this right out of the box, while also providing a nice tool which allows you to take more advantage of it.
First things first... Python has its own help system (!) which might not be a full substitute for reference documentation, but it can still be quite useful:
Code:
>>> help
Welcome to Python 3.13's help utility! If this is your first time using
Python, you should definitely check out the tutorial at
https://docs.python.org/3.13/tutorial/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To get a list of available
modules, keywords, symbols, or topics, enter "modules", "keywords",
"symbols", or "topics".
Each module also comes with a one-line summary of what it does; to list
the modules whose name or summary contain a given string such as "spam",
enter "modules spam".
To quit this help utility and return to the interpreter,
enter "q", "quit" or "exit".
So here's where things get more interesting: if you provide such a docstring below any kind of definition then you'll automatically document whatever object you just defined. So... whenever you create (or define) a new function, (global) variable, class or a method: one docstring is all you need to provide documentation. And the best part? You can either use oneliners, or write out a small summary, there are no strict rules here.
And all those docstrings can then be automatically used by Python. Either within its help system (as shown above), or when using the pydoc utility: this can parse any Python script and print (or save) a summary, either in text or HTML format. Oh, and that pydoc utility? It's actually a Python script of its own
Of course there are many more (awesome) reasons to start using Python (like being able to run a debugger straight from the command line!), but these are simply my personal favorites.
How to get started?
Well, as one could imagine: Python is fully included (and supported) within the ports collection. At the time of writing you can pick between Python 3.10 all the way up to 3.14. SO... if you plan on building Python yourself then do take note of /usr/ports/Mk/bsd.default-versions.mk; right now the default version is 3.11, but you're fully free to use another of course. Just make sure to define this in your /etc/make.conf.Which then begs the question: "What version should you pick?". When in doubt then I'd stick with the default, however... it might be useful to start by checking the active Python releases. Right now 3.12 seems like a more logical choice to me, also considering that it'll be supported for another 2 years. Or, if you want to go a little more "bleeding edge" but without the actual risks then 3.13 is also a solid choice.
Once you have this out of the way then it's time to install your pick. In addition I also suggest installing lang/python-doc-text and/or lang/python-doc-html because not only does this provide some solid information, it also includes the official Python tutorial which, in my opinion anyway, can be an awesome help & reference. Fun fact: this tutorial also seriously helped me out to get started with Python.
Oh, and of course you can also install binary packages if you'd like:
# pkg install python313 python-doc-text for example.Libraries
As you might know Python is a very popular programming language, and there are also a lot of people who spend their time coding API's and libraries which can help to make our lives a little easier. Many of these libraries are also available in the ports collection. Some examples:- www/py-scrapy => Solid web crawling framework which can make it (very) easy to build your own crawlers.
- security/py-gnupg => Fancy utilizing GnuPG in your Python scripts? Well, this could be a great help for that.
- devel/py-gitpython => Want to interact with Git to automate a few tasks? This could help...
- www/py-playwright => Need to automate the testing of a website? This library can provide some awesome help.
When you install some of these libraries then they become available system-wide: so, accessible for all your scripts. Usually this isn't much of a problem, but what if you need a specific version of a library, or maybe another variant? Or what if... some names overlap?
PIP
In case you're wondering: Pip Installs Packages
Python has its own package manager called PIP, and as you might have guessed: it's even written in Python itself. And PIP can also be used to install packages like the ones I mentioned above. By default PIP is only accessible on FreeBSD once you set up a so called virtual environment:
Code:
peter@zefiris:/home/peter/temp $ pip
/usr/local/bin/ksh: pip: not found
peter@zefiris:/home/peter/temp $ python -m pip
/usr/local/bin/python: No module named pip
peter@zefiris:/home/peter/temp $ python -m venv fbsd-test
peter@zefiris:/home/peter/temp $ cd fbsd-test/
peter@zefiris:/home/peter/temp/fbsd-test $ . bin/activate
(fbsd-test) peter@zefiris:/home/peter/temp/fbsd-test $ python -m pip --version
pip 26.0.1 from /home/peter/temp/fbsd-test/lib/python3.13/site-packages/pip (python 3.13)
(fbsd-test) peter@zefiris:/home/peter/temp/fbsd-test $
Code:
(fbsd-test) peter@zefiris:/home/peter/temp/fbsd-test $ which pip
/home/peter/temp/fbsd-test/bin/pip
(fbsd-test) peter@zefiris:/home/peter/temp/fbsd-test $ pip install pycryptodome
Collecting pycryptodome
Downloading pycryptodome-3.23.0.tar.gz (4.9 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.9/4.9 MB 43.8 MB/s 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pycryptodome
Building wheel for pycryptodome (pyproject.toml) ... done
Created wheel for pycryptodome: filename=pycryptodome-3.23.0-cp37-abi3-freebsd_14_4_release_p1_amd64.whl size=1726115 sha256=85e8503b8cca046108f081d42c82f533c88e3151c4dc9d69aee5d53198ee9263
Stored in directory: /home/peter/.cache/pip/wheels/29/eb/c7/c569c89bdc7331f61e744a1847d02798ce31bf1bd1cb13cb33
Successfully built pycryptodome
Installing collected packages: pycryptodome
Successfully installed pycryptodome-3.23.0
So now I have access to all the features of pycryptodome, but only within this virtual environment, and also only when it's activated (noticed the change in my prompt btw?):
Code:
(fbsd-test) peter@zefiris:/home/peter/temp/fbsd-test $ python -c "import Crypto"
(fbsd-test) peter@zefiris:/home/peter/temp/fbsd-test $ deactivate
peter@zefiris:/home/peter/temp/fbsd-test $ python -c "import Crypto"
Traceback (most recent call last):
File "<string>", line 1, in <module>
import Crypto
ModuleNotFoundError: No module named 'Crypto'
And now?
Well, if you followed my tutorial up to this point then you should have everything installed to start using Python. And the best way to learn... is to actually start using it. So... why not build yourself a Python script (remember the shebang!) and then try to make it "do" something? Seriously, the best way to learn a programming language is to simply start using it.
And there you have it!
Thanks for reading, I hope you guys found this useful.