  We introduce a topological flux function to quantify the topology of magnetic
braids: non-zero, line-tied magnetic fields whose field lines all connect
between two boundaries. This scalar function is an ideal invariant defined on a
cross-section of the magnetic field, and measures the average poloidal magnetic
flux around any given field line, or the average pairwise crossing number
between a given field line and all others. Moreover, its integral over the
cross-section yields the relative magnetic helicity. Using the fact that the
flux function is also an action in the Hamiltonian formulation of the field
line equations, we prove that it uniquely characterizes the field line mapping
and hence the magnetic topology.
