Skip to content
DocumentationSchemaManagerSchemaManager

SchemaManager

A schema represents a constructed flow diagram in the editor composed of foundational Blocks. It encapsulates all the Blocks on the editor, along with the connections between them. Schemas are central to defining and managing workflows in the system.

SchemaManager Implementation Example

Initializing a SchemaManager

The SchemaManager class is used to manage schemas. It provides methods for saving, loading, and listing schema names. To initialize it, you can use the default constructor. This creates a schemas.barfi database file in the current working directory. You can also specify a custom file path and file name to store the schemas.

app.py
from barfi.flow import SchemaManager
 
# ... existing code ...
 
# 01: Initialize a SchemaManager with default file path './schemas.barfi'
my_schema_manager = SchemaManager()

Saving a Schema

When a schema is saved, it is added to the database file initialized with the SchemaManager. Each schema requires a unique name to be saved successfully. This mechanism ensures that schemas can be preserved and reused as needed.

app.py
# 02: Save a schema with a unique name
my_schema_manager.save_schema(schema_name="my_schema", flow_schema=my_flow_schema)

Loading a Schema

Schemas can be loaded into the application using the load_schema method of the SchemaManager class. This feature eliminates the need to recreate schemas from scratch, streamlining the workflow efficiency.

app.py
# 03: Load a schema by name
my_flow_schema = my_schema_manager.load_schema(schema_name="my_schema")