Function Code Anatomy
With your function project made and the code available on GitHub, you can start making it your own. Where you choose to develop (locally or codespace) is up to you. Assuming you work locally, clone the repository linked under Source on the function’s page; the sections below cover the code architecture. The template projects for specklepy and speckle-sharp include all required for a working function to deploy in an automation. The anatomy doesn’t have to match exactly, but it does have to have these key components:Function Inputs
Python
This is aFunctionInputs class subclassing AutomateBase from the Python Automate SDK (speckle_automate, part of specklepy).
Define its properties with Pydantic Field objects to control the fields shown in the function inputs UI. A SecretStr field is a secret: Automate masks it in the UI and stores it encrypted.
main.py
C# (.NET)
FunctionInputs must be a struct.
FunctionInputs.cs
Secrets Management
It is possible to flag function inputs so that the Automate UI will obfuscate them on entry in the typical web fashion (********). This will also cause Automate to store these as encrypted and only pass them as plain text within AutomationContext at runtime.
C# (.NET)
FunctionInputs.cs
Python
main.py
Run Entry Points
In the GitHub action, there is a space to define the eventually built function as it would be executed from a command line with eitherdotnet SpeckleAutomateDotnetExample.dll or python main.py run, which is the general rule for all Automate functions, whether defined with the template projects or not.
Python
The essential execution of a Python SDK function is:main.py
FunctionInputs is the class described earlier, and automate_function is the single entry point to your business logic. Define it with plain def, not async def: the runner calls it synchronously, so a coroutine would never run. You can define as many classes, external modules, and functions within your repository code, but this will be your key function.
C# (.NET)
The template’sProgram.cs registers the Automate SDK, resolves the runner, and passes it your function:
Program.cs
FunctionInputs is the struct described earlier. AutomateFunction is a class with a Run(IAutomationContext context, FunctionInputs inputs) method that returns a Task. It can hold all of your business logic, or be the entry point to the rest of your classes and methods.