The context concept allows callers to work in environments with different sets of YANG modules.
The first step with libyang is to create a new context using ly_ctx_new(). It returns a handler used in the following work. Note that the context is supposed to provide a stable environment for work with the data. Therefore the caller should prepare a complete context and after starting working with the data, the context and its content should not change. If it does, in most cases it leads to the context being recompiled and any parsed data invalid. Despite the API not enforcing this approach, it may change in future versions in the form of a locking mechanism which would allow further optimization of data manipulation. Also note that modules cannot be removed from their context. If you need to change the set of the schema modules in the context, the recommended way is to create a new context. To remove the context, there is ly_ctx_destroy() function.
The context has several options changing behavior when processing YANG modules being inserted. The specific behavior is mentioned below. All the options can be set as a parameter when the context is being created or later with ly_ctx_set_options().
When creating a new context, another optional parameter is search_dir It provide directory where libyang will automatically search for YANG modules being imported or included. There is actually a set of search paths which can be later modified using ly_ctx_set_searchdir(), ly_ctx_unset_searchdir() and ly_ctx_unset_searchdir_last() functions. Before the values in the set are used, also the current working directory is (non-recursively) searched. For the case of the explicitly set search directories, they are searched recursively - all their subdirectories (and symlinks) are taken into account. Searching in the current working directory can be avoided with the context's