How can I run blender from command line or a python script without opening a GUI?
Command-line / subprocess

You can use subprocess to run blender (like any other application) from python.
Use the -b / --background switch to run blender in the backgroud (GUI-less).
Use the -P &lt;filename&gt; / --python &lt;filename&gt; switch to load desired python script.

Or use --python-console to run python from stdin.



Example: blender --background --python myscript.py
See: https://docs.blender.org/manual/en/latest/advanced/command_line/arguments.html
As module
This is an experimental feature and not enabled by default, but Blender can be compiled as a python module.

This allows 'bpy' to be imported from python or other applications/IDE's which embed python