By default, all logs within a project are stored in the default context (represented by the empty string "").
Copy
Ask AI
unify.log(x=0, y=1, z=2)
When no context is specified in the interface or the table, then the default context is used.
However, you can group your logs into non-overlapping contexts, which can then be displayed in separate tables.
These can also be arbitrarily nested, where each context string is joined via / to define the full context path.
Copy
Ask AI
import unifywith unify.Context("Sciences"): with unify.Context("Maths"): unify.log( name="Zoe", question="what is 1 + 1?", region="US" ) with unify.Context("Physics"): unify.log( name="John", question="what is the speed of light?", region="EU" )with unify.Context("Arts"): with unify.Context("Literature"): unify.log( name="Jane", question="What does this sentence convey?", region="UK" )
The “Sciences” context cannot itself be selected in a table (there is no data),
but it forms part of the directory structure for selecting the available contexts.
However, “Sciences” can be selected as the context of the tab in the interface,
which limits the search space for each table within the tab.
By default, unify.Context("...") also changes the behaviour of get_logs, returning only the logs relevant within the context.
Copy
Ask AI
import unifywith unify.Context("Sciences"): with unify.Context("Maths"): unify.log( name="Zoe", question="what is 1 + 1?", region="US" ) assert len(unify.get_logs()) == 1 with unify.Context("Physics"): unify.log( name="John", question="what is the speed of light?", region="EU" ) assert len(unify.get_logs()) == 1
This behaviour can be changed by setting unify.Context("...", mode="read") which will only set the context for log getting,
and unify.Context("...", mode="write") which will only set the context for log setting.
This makes it easy to quickly get/set different logs for different purposes throughout your codebase,
without needing to manage contexts via local variables.