Skip to content

Utility Functions

Angreal provides utility functions for common operations when working with projects and commands.

These utilities help with:

  • Project Structure - Locating the project root directory
  • Context Access - Retrieving template variables from project initialization
  • Version Checking - Ensuring the right Angreal version is used
  • Command Aliasing - Creating custom command names for white-labeling
Function Description Documentation
get_root Get the root directory of the Angreal project API Reference
get_context Get the context from angreal.toml used to render the template API Reference
required_version Check for minimum required Angreal version API Reference
register_entrypoint Create a command alias for angreal (white-labeling) API Reference
list_entrypoints List all registered command aliases API Reference
unregister_entrypoint Remove a command alias API Reference
cleanup_entrypoints Remove all registered command aliases API Reference
import angreal
import os
# Check for required version
angreal.required_version("2.0.0")
# Get the project root
root_dir = angreal.get_root()
templates_dir = os.path.join(root_dir, "templates")
print(f"Project root: {root_dir}")
print(f"Templates directory: {templates_dir}")
import angreal
# Get the context from angreal.toml
context = angreal.get_context()
if context:
print("Project name:", context.get("project_name", "Not set"))
print("Version:", context.get("version", "Not set"))
else:
print("No context found (not in an angreal project)")
import angreal
# Create a command alias for white-labeling
angreal.register_entrypoint("mycompany-tool")
# List all registered aliases
aliases = angreal.list_entrypoints()
print("Registered aliases:", aliases)
# Remove an alias
angreal.unregister_entrypoint("mycompany-tool")
# Clean up all aliases
angreal.cleanup_entrypoints()