How to use python in Editor to build lighting and package project?

Is it even possible?

I’m trying to look into the concept of using Python in editor to create levels, setup assets, build lights, and finally build the package. (Looking for quick turnaround from customer assets to final playable result).

From my research and experimentation so far I know we can create levels and populate it with assets, but I seem unable to find the correct API calls to start the light-bake processes or the packaging processes. I’m finding python classes to make LightingBuild settings, and ProjectPackaging settings, but nothing to actually start the process.

What are my options here, or can you help point me in the correct direction?
Any help would be greatly appreciated, thanks.

Link to Python API for reference: Unreal Python API Documentation — Unreal Python 4.27 (Experimental) documentation

Still need answer and assistance, but will provide update on current research, in the event someone else is looking to solve the same issues.
Figured out how to call C++ code from a python script from this very helpful video. Not at all complicated as everything (may be some exceptions) exposed to Blueprints will also be exposed to Python.


#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "PythonFunctions.generated.h"

class PYTHONPROJECT_API UPythonFunctions : public UBlueprintFunctionLibrary

	static void CalledFromPython(FString InputString);


#include "../Public/PythonFunctions.h"

void UPythonFunctions::CalledFromPython(FString InputString)
	UE_LOG(LogTemp, Error, TEXT("%s"), *InputString);

Python script:

import unreal
unreal.PythonFunctions.called_from_python("Hello world")

Console output:

LogPython: unreal.PythonFunctions.called_from_python("Hello world")
LogTemp: Error: Hello world

(Exactly as expected)

Things to note:
Functions declared in PascalCase in C++ will be converted to snake_case within the unreal python module.

Further research:
To be able to call the build lighting commands, or the package project commands, it seems I either will need to go into the engine and expose that code to Blueprints/Python, or write some custom C++ code (Plugin perhaps) to call it for me.

I’m looking for an answer to this as well. We need to build multiple lighting scenarios per map, having the option to automate that via Python would be very helpful.

Thank you for your clue, I followed this method and find a function in c++ file.
in the header file “Editor/LevelEditor/Public/LevelEditorActions.h” FlevelEditorActionCallbacks::BuildLightingOnly_execute().

I tried to include the header file and call the function, but it doesn’t pass the compiling.

Did you find any wrokaround to handle this? it will be very helpfull

I have not, sorry. The project got closed down and I have since moved on to other things.