Getting Started with Python
This guide shows how to create your first Azul application in Python.
Quick Start
Install Azul from PyPI:
Or download from releases.
Hello World
# Your application state
= 0
# Layout function - converts state to UI
return \
\
# Run the app
=
Adding Callbacks
= 0
# Callback function
+= 1
return
= \
\
# Attach callback
=
return \
\
\
=
RefAny and Data Types
Any Python object can be used where RefAny is required:
=
= 0
# App::new() takes a RefAny - pass your Python object directly
=
Union Enums
Union enums have static constructors and a match() function:
# Create union enum
=
# Pattern match
, =
== :
Constructors
Default constructors take all arguments in field order:
# API: struct ColorU { r: u8, g: u8, b: u8, a: u8 }
= # r, g, b, a
# Named explicit constructor
= # Not Dom.new(...)
Vectors and Options
*Vec types accept Python lists, *Option types handle None:
# Get monitors - returns list
=
# Optional return value
=
Debug Printing
All types implement __str__() and __repr__():
=
# ColorU { r: 255, g: 0, b: 0, a: 255 }
Nested Struct Modification
Due to a PyO3 bug, nested struct modification requires copying:
# This doesn't work:
=
# Workaround:
=
=
=
=
=
Enum Comparison
Simple enums support comparison:
=
Complete Example
=
=
=
return
return
=
return \
\
\
\
=
Next Steps
- CSS Styling - Supported CSS properties
- Widgets - Interactive components
- Architecture - Framework design