SchemaManager
API Reference
The SchemaManager class is a utility for managing schema operations, including loading, saving, updating, and deleting schemas. It provides persistence through a gzipped JSON file named schemas.barfi by default. This documentation outlines its key attributes, methods, and usage examples.
Class barfi.flow.SchemaManager
Manages schema operations for loading, saving, and deleting schemas.
Parameters
- filename (str, optional): The name of the schema storage file. Default is “schemas.barfi”.
- filepath (str, optional): The directory path for schema storage. Default is ”./”.
Example
from barfi.flow import SchemaManager
manager = SchemaManager()
Properties
- schema_names (List[str]): A list of all schema names currently stored.
Methods
save_schema(schema_name: str, flow_schema: FlowSchema)
Stores a new schema with the specified name.
Parameters
- schema_name (str): Unique identifier for the schema.
- flow_schema (FlowSchema): The schema configuration to store.
Raises
- ValueError: If a schema with the given name already exists.
Example
manager.save_schema("example_schema", schema)
update_schema(schema_name: str, flow_schema: FlowSchema)
Updates an existing schema with new schema configuration.
Parameters
- schema_name (str): Identifier of the schema to update.
- flow_schema (FlowSchema): New schema configuration.
Raises
- ValueError: If the schema name doesn’t exist in storage.
Example
manager.update_schema("example_schema", updated_schema)
upsert_schema(schema_name: str, flow_schema: FlowSchema)
Creates or updates a schema. If the schema exists, it updates it; otherwise, it creates a new one.
Parameters
- schema_name (str): Identifier of the schema to upsert.
- flow_schema (FlowSchema): Schema configuration.
Example
manager.upsert_schema("example_schema", new_schema)
load_schema(schema_name: str) -> FlowSchema
Loads a schema by its name.
Parameters
- schema_name (str): Identifier of the schema to load.
Returns
- FlowSchema: The schema configuration data.
Example
schema = manager.load_schema("example_schema")
delete_schema(schema_name: str)
Deletes a schema by its name.
Parameters
- schema_name (str): Identifier of the schema to delete.
Raises
- ValueError: If the schema name doesn’t exist in storage.
Example
manager.delete_schema("example_schema")