SDK Reference¶
bani.sdk.bani
¶
Top-level Bani class for loading and running migrations.
BaniProject
¶
Wrapper around a loaded ProjectModel with validation and execution methods.
Source code in src/bani/sdk/bani.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
__init__(project)
¶
Initialize a BaniProject.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
ProjectModel
|
The ProjectModel to wrap. |
required |
validate()
¶
Validate the project configuration.
Returns:
| Type | Description |
|---|---|
tuple[bool, list[str]]
|
A tuple of (is_valid, error_messages). |
Source code in src/bani/sdk/bani.py
run(on_progress=None, resume=False, cancel_event=None, checkpoint=None, projects_dir='~/.bani/projects')
¶
Execute the migration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_progress
|
Callable[[Any], None] | None
|
Optional callback for progress updates. |
None
|
resume
|
bool
|
If |
False
|
cancel_event
|
Any | None
|
Optional |
None
|
checkpoint
|
Any | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
MigrationResult
|
A MigrationResult with execution summary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the project is invalid. |
Exception
|
If migration execution fails. |
Source code in src/bani/sdk/bani.py
preview(tables=None, sample_size=10)
¶
Preview data from the source database.
Delegates to :func:bani.application.preview.preview_source for
the actual introspection and sampling logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tables
|
list[str] | None
|
Optional list of table names to preview. If |
None
|
sample_size
|
int
|
Number of rows to sample per table. |
10
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
PreviewResult
|
class: |
Source code in src/bani/sdk/bani.py
Bani
¶
Top-level entry point for Bani operations.
Source code in src/bani/sdk/bani.py
load(path)
staticmethod
¶
Load a BDL project file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the BDL file. |
required |
Returns:
| Type | Description |
|---|---|
BaniProject
|
A BaniProject ready for validation and execution. |
Raises:
| Type | Description |
|---|---|
BDLValidationError
|
If parsing fails. |
Source code in src/bani/sdk/bani.py
validate_file(path)
staticmethod
¶
Validate a BDL file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the BDL file. |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, list[str]]
|
A tuple of (is_valid, error_messages). |
Source code in src/bani/sdk/bani.py
bani.sdk.project_builder
¶
Fluent builder for ProjectModel construction (Section 18.3).
ProjectBuilder
¶
Fluent builder for constructing ProjectModel instances.
Source code in src/bani/sdk/project_builder.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
__init__(name)
¶
Initialize a new project builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The project name. |
required |
Source code in src/bani/sdk/project_builder.py
source(dialect, host='', port=0, database='', username_env='', password_env='', **extra)
¶
Configure the source database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dialect
|
str
|
Database dialect (e.g. "postgresql", "mysql"). |
required |
host
|
str
|
Database host. |
''
|
port
|
int
|
Database port. |
0
|
database
|
str
|
Database name. |
''
|
username_env
|
str
|
Environment variable name for username. |
''
|
password_env
|
str
|
Environment variable name for password. |
''
|
**extra
|
str
|
Additional connector-specific configuration. |
{}
|
Returns:
| Type | Description |
|---|---|
ProjectBuilder
|
This builder for method chaining. |
Source code in src/bani/sdk/project_builder.py
target(dialect, host='', port=0, database='', username_env='', password_env='', **extra)
¶
Configure the target database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dialect
|
str
|
Database dialect (e.g. "postgresql", "mysql"). |
required |
host
|
str
|
Database host. |
''
|
port
|
int
|
Database port. |
0
|
database
|
str
|
Database name. |
''
|
username_env
|
str
|
Environment variable name for username. |
''
|
password_env
|
str
|
Environment variable name for password. |
''
|
**extra
|
str
|
Additional connector-specific configuration. |
{}
|
Returns:
| Type | Description |
|---|---|
ProjectBuilder
|
This builder for method chaining. |
Source code in src/bani/sdk/project_builder.py
include_tables(tables)
¶
Include only these tables in the migration.
Tables are specified in "schema.table" format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tables
|
list[str]
|
List of fully qualified table names to include. |
required |
Returns:
| Type | Description |
|---|---|
ProjectBuilder
|
This builder for method chaining. |
Source code in src/bani/sdk/project_builder.py
exclude_tables(tables)
¶
Exclude these tables from the migration.
Tables are specified in "schema.table" format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tables
|
list[str]
|
List of fully qualified table names to exclude. |
required |
Returns:
| Type | Description |
|---|---|
ProjectBuilder
|
This builder for method chaining. |
Source code in src/bani/sdk/project_builder.py
type_mapping(source_type, target_type)
¶
Add a type mapping override.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_type
|
str
|
Source database type. |
required |
target_type
|
str
|
Target database type. |
required |
Returns:
| Type | Description |
|---|---|
ProjectBuilder
|
This builder for method chaining. |
Source code in src/bani/sdk/project_builder.py
batch_size(size)
¶
Set the batch size for data transfer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of rows per batch. |
required |
Returns:
| Type | Description |
|---|---|
ProjectBuilder
|
This builder for method chaining. |
Source code in src/bani/sdk/project_builder.py
parallel_workers(workers)
¶
Set the number of parallel workers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workers
|
int
|
Number of parallel workers. |
required |
Returns:
| Type | Description |
|---|---|
ProjectBuilder
|
This builder for method chaining. |
Source code in src/bani/sdk/project_builder.py
memory_limit(mb)
¶
Set the memory limit in MB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mb
|
int
|
Memory limit in megabytes. |
required |
Returns:
| Type | Description |
|---|---|
ProjectBuilder
|
This builder for method chaining. |
description(desc)
¶
Set the project description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desc
|
str
|
Project description. |
required |
Returns:
| Type | Description |
|---|---|
ProjectBuilder
|
This builder for method chaining. |
author(name)
¶
Set the project author.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Author name. |
required |
Returns:
| Type | Description |
|---|---|
ProjectBuilder
|
This builder for method chaining. |
tags(tags)
¶
Set project tags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tags
|
list[str]
|
List of tags. |
required |
Returns:
| Type | Description |
|---|---|
ProjectBuilder
|
This builder for method chaining. |
build()
¶
Build and return the ProjectModel.
Returns:
| Type | Description |
|---|---|
ProjectModel
|
The constructed ProjectModel. |
Source code in src/bani/sdk/project_builder.py
bani.sdk.schema_inspector
¶
Schema introspection via connectors.
SchemaInspector
¶
Inspects database schema via connector registry.
Source code in src/bani/sdk/schema_inspector.py
inspect(dialect, host='', port=0, database='', username_env='', password_env='', **kwargs)
staticmethod
¶
Introspect a database schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dialect
|
str
|
Database dialect (e.g. "postgresql", "mysql"). |
required |
host
|
str
|
Database host. |
''
|
port
|
int
|
Database port. |
0
|
database
|
str
|
Database name. |
''
|
username_env
|
str
|
Environment variable name for username. |
''
|
password_env
|
str
|
Environment variable name for password. |
''
|
**kwargs
|
Any
|
Additional connector-specific arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
DatabaseSchema
|
The introspected DatabaseSchema. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no connector is registered for the dialect. |
Exception
|
If connection or introspection fails. |