utils

class aind_behavior_services.utils.BonsaiSgenSerializers(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

JSON = 'NewtonsoftJson'[source]
NONE = 'None'[source]
YAML = 'YamlDotNet'[source]
class aind_behavior_services.utils.CustomGenerateJsonSchema(*args, **kwargs)[source]

Bases: GenerateJsonSchema

enum_schema(schema: EnumSchema) Dict[str, Any][source]

Generates a JSON schema that matches an Enum value.

Parameters:

schema – The core schema.

Returns:

The generated JSON schema.

get_flattened_oneof(schemas: list[Dict[str, Any]]) Dict[str, Any][source]
literal_schema(schema: LiteralSchema) Dict[str, Any][source]

Generates a JSON schema that matches a literal value.

Parameters:

schema – The core schema.

Returns:

The generated JSON schema.

nullable_schema(schema: NullableSchema) Dict[str, Any][source]

Generates a JSON schema that matches a schema that allows null values.

Parameters:

schema – The core schema.

Returns:

The generated JSON schema.

union_schema(schema: UnionSchema) Dict[str, Any][source]

Generates a JSON schema that matches a schema that allows values matching any of the given schemas.

Parameters:

schema – The core schema.

Returns:

The generated JSON schema.

aind_behavior_services.utils.bonsai_sgen(schema_path: PathLike, output_path: PathLike, namespace: str = 'DataSchema', root_element: str | None = None, serializer: List[BonsaiSgenSerializers] | None = None, executable: PathLike | str = 'dotnet tool run bonsai.sgen') CompletedProcess[source]

Runs Bonsai.SGen to generate a Bonsai-compatible schema from a json-schema model For more information run bonsai.sgen –help in the command line.

Returns:

The result of running the command.

Return type:

CompletedProcess

Parameters:
  • schema_path (PathLike) – Target Json Schema file

  • output_path (PathLike) – Specifies the name of the file containing the generated code.

  • namespace (Optional[str], optional) – Specifies the namespace to use for all generated serialization classes. Defaults to DataSchema.

  • root_element (Optional[str], optional) – Specifies the name of the class used to represent the schema root element. If None, it will use the json schema root element. Defaults to None.

  • serializer (Optional[List[BonsaiSgenSerializers]], optional) – Specifies the serializer data annotations to include in the generated classes. Defaults to None.

aind_behavior_services.utils.convert_pydantic_to_bonsai(models: Dict[str, List[Type[BaseModel]] | Type[BaseModel]], namespace: str = 'DataSchema', schema_path: PathLike = PosixPath('src/DataSchemas'), output_path: PathLike = PosixPath('src/Extensions'), serializer: List[BonsaiSgenSerializers] | None = None, skip_sgen: bool = False, export_schema_kwargs: Dict[str, Any] | None = None) Dict[str, CompletedProcess | None][source]
aind_behavior_services.utils.export_schema(model: ~typing.List[~typing.Type[~pydantic.main.BaseModel]] | ~typing.Type[~pydantic.main.BaseModel], schema_generator: ~typing.Type[~pydantic.json_schema.GenerateJsonSchema] = <class 'aind_behavior_services.utils.CustomGenerateJsonSchema'>, mode: ~typing.Literal['validation', 'serialization'] = 'serialization', def_keyword: str = 'definitions', models_title: str | None = None)[source]

Export the schema of a model to a json file

aind_behavior_services.utils.format_datetime(value: datetime, is_tz_strict: bool = False) str[source]
aind_behavior_services.utils.model_from_json_file(json_path: PathLike | str, model: type[TModel]) TModel[source]
aind_behavior_services.utils.open_bonsai_process(workflow_file: PathLike | str, bonsai_exe: PathLike | str = 'bonsai/bonsai.exe', is_editor_mode: bool = True, is_start_flag: bool = True, layout: PathLike | str | None = None, additional_properties: Dict[str, str] | None = None, log_file_name: str | None = None, cwd: PathLike | str | None = None, creation_flags: int | None = None, print_cmd: bool = False) Popen[source]
aind_behavior_services.utils.pascal_to_snake_case(s: str) str[source]

Converts a PascalCase string to snake_case.

Parameters:

s (str) – The PascalCase string to be converted.

Returns:

The snake_case string.

Return type:

str

aind_behavior_services.utils.run_bonsai_process(workflow_file: PathLike | str, bonsai_exe: PathLike | str = 'bonsai/bonsai.exe', is_editor_mode: bool = True, is_start_flag: bool = True, layout: PathLike | str | None = None, additional_properties: Dict[str, str] | None = None, cwd: PathLike | str | None = None, timeout: float | None = None, print_cmd: bool = False) CompletedProcess[source]
aind_behavior_services.utils.screaming_snake_case_to_pascal_case(s: str) str[source]

Converts a SCREAMING_SNAKE_CASE string to PascalCase.

Parameters:

s (str) – The SCREAMING_SNAKE_CASE string to be converted.

Returns:

The PascalCase string.

Return type:

str

aind_behavior_services.utils.snake_to_pascal_case(s: str) str[source]

Converts a snake_case string to PascalCase.

Parameters:

s (str) – The snake_case string to be converted.

Returns:

The PascalCase string.

Return type:

str

aind_behavior_services.utils.utcnow() datetime[source]