API Reference
This is the API reference for the mitm_tooling package.
It includes MITM model definition representation,
MITM data representation, im/export and transformation,
Superset Asset Generation,
and MITM data extraction from relational databases (and files).
MITM Definitions
MITMDefinition
Bases: BaseModel
This model represents a MITM metamodel via a set of concepts, their properties, and relations.
Source code in mitm_tooling/definition/definition_representation.py
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 | |
MITM Data Representation
Im/Exporting
ExportableSQLiteExport
Bases: MITMExport
Export a BoundExportable to the specific SQLite file format designed for MITMs.
Source code in mitm_tooling/io/sqlite.py
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 | |
FolderExport
Bases: MITMExport
Export MITMData to a folder with the structure of the zipped file format designed for MITMs.
See ZippedExport for more details.
Source code in mitm_tooling/io/folder.py
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 | |
FolderImport
Bases: MITMImport
Import a folder with the structure of the zipped file format designed for MITMs.
See ZippedImport for more details.
Source code in mitm_tooling/io/folder.py
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 | |
MITMDataFramesSQLiteExport
Bases: MITMExport
Directly export MITMDataFrames to the specific SQLite file format designed for MITMs.
Source code in mitm_tooling/io/sqlite.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
SQLiteExport
Bases: MITMExport
Export MITMData to the specific SQlite file format designed for MITMs.
Source code in mitm_tooling/io/sqlite.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
SQLiteImport
Bases: StreamingMITMImport
Import of the specific SQLite file format designed for MITMs.
Source code in mitm_tooling/io/sqlite.py
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 | |
StreamingZippedExport
Bases: MITMExport
Export StreamingMITMData to a streamed zip file in the format designed for MITMs.
See also ZippedExport.
Source code in mitm_tooling/io/zip.py
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 | |
ZippedExport
Bases: MITMExport
Export MITMData to the specific zip file format designed for MITMs.
Source code in mitm_tooling/io/zip.py
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 | |
ZippedImport
Bases: MITMImport
Import of the specific zip file format designed for MITMs.
The data source is expected to be a zipped archive of CSV files.
At least a header.csv file is expected.
The other CSVs are expected to be named according to the pluralized concept names of defined in by the specified MITM.
The CSVs themselves are expected to be in the format of MITMData.
Source code in mitm_tooling/io/zip.py
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 | |
read_file(source: FilePath, variant: FileRepresentationVariant = 'zip', mitm: MITM | None = None, header_only: bool = False, **kwargs) -> MITMData | None
Read a file into a MITMData object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
FilePath
|
a readable byte or text buffer, or a file path |
required |
variant
|
FileRepresentationVariant
|
the file representation variant, defaults to 'zip' |
'zip'
|
mitm
|
MITM | None
|
the target MITM, is attempted to be inferred from the file path if not specified |
None
|
header_only
|
bool
|
whether to read only the header, skipping the (potentially large) data files |
False
|
kwargs
|
any additional keyword arguments to pass to the underlying |
{}
|
Returns:
| Type | Description |
|---|---|
MITMData | None
|
the |
Source code in mitm_tooling/io/interface.py
16 17 18 19 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 | |
read_folder(source: DataSource, mitm: MITM | None = None, header_only: bool = False, **kwargs) -> MITMData | None
Read a folder into a MITMData object. See read_file() for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
a readable byte or text buffer, or a file path |
required |
mitm
|
MITM | None
|
the target MITM, is attempted to be inferred from the file path if not specified |
None
|
header_only
|
bool
|
whether to read only the header, skipping the (potentially large) data files |
False
|
kwargs
|
any additional keyword arguments to pass to the underlying |
{}
|
Returns:
| Type | Description |
|---|---|
MITMData | None
|
the |
Source code in mitm_tooling/io/interface.py
147 148 149 150 151 152 153 154 155 156 157 | |
read_sqlite(source: DataSource, mitm: MITM | None = None, header_only: bool = False, **kwargs) -> MITMData | None
Read a SQLite file into a MITMData object. See read_file() for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
a readable byte or text buffer, or a file path |
required |
mitm
|
MITM | None
|
the target MITM, is attempted to be inferred from the file path if not specified |
None
|
header_only
|
bool
|
whether to read only the header, skipping the (potentially large) data files |
False
|
kwargs
|
any additional keyword arguments to pass to the underlying |
{}
|
Returns:
| Type | Description |
|---|---|
MITMData | None
|
the |
Source code in mitm_tooling/io/interface.py
123 124 125 126 127 128 129 130 131 132 133 | |
read_zip(source: DataSource, mitm: MITM | None = None, header_only: bool = False, **kwargs) -> MITMData | None
Read a zip file into a MITMData object. See read_file() for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
a readable byte or text buffer, or a file path |
required |
mitm
|
MITM | None
|
the target MITM, is attempted to be inferred from the file path if not specified |
None
|
header_only
|
bool
|
whether to read only the header, skipping the (potentially large) data files |
False
|
kwargs
|
any additional keyword arguments to pass to the underlying |
{}
|
Returns:
| Type | Description |
|---|---|
MITMData | None
|
the |
Source code in mitm_tooling/io/interface.py
100 101 102 103 104 105 106 107 108 109 110 | |
write_file(target: FilePath, mitm_data: MITMData, variant: FileRepresentationVariant = 'zip', **kwargs)
Write mitm_data to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
FilePath
|
the output file path |
required |
mitm_data
|
MITMData
|
the |
required |
variant
|
FileRepresentationVariant
|
the file representation variant, defaults to 'zip' |
'zip'
|
Source code in mitm_tooling/io/interface.py
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 | |
write_folder(target: FilePath, mitm_data: MITMData) -> None
Write mitm_data to a folder. See read_file() for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
FilePath
|
the output file path |
required |
mitm_data
|
MITMData
|
the |
required |
Source code in mitm_tooling/io/interface.py
160 161 162 163 164 165 166 167 | |
write_sqlite(target: FilePath, mitm_data: MITMData) -> None
Write mitm_data to a SQLite file. See read_file() for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
FilePath
|
the output file path |
required |
mitm_data
|
MITMData
|
the |
required |
Source code in mitm_tooling/io/interface.py
136 137 138 139 140 141 142 143 144 | |
write_zip(target: FilePath, mitm_data: MITMData) -> None
Write mitm_data to a zip file. See read_file() for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
FilePath
|
the output file path |
required |
mitm_data
|
MITMData
|
the |
required |
Source code in mitm_tooling/io/interface.py
113 114 115 116 117 118 119 120 | |
Intermediate
An intermediate representation of MITM data, which was manually designed with the consideration of human-accessibility over performance and efficiency.
Header
Bases: BaseModel
This (immutable) model represents the full type information of a MITM data set.
Source code in mitm_tooling/representation/intermediate/header.py
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 | |
HeaderEntry
Bases: BaseModel
This (immutable) model represents a single entry in a Header, i.e., a type definition.
Source code in mitm_tooling/representation/intermediate/header.py
19 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 | |
MITMData
Bases: Iterable[tuple[ConceptName, DataFrame]], BaseModel
This model represents MITM data in a semi-compacted form; essentially the proposed csv file format.
The individual DataFrames are expected to have fixed columns, corresponding to the type information in the header.
In particular, each DataFrame should have the static columns as defined the concept it belongs to,
and additionally a variable number of attribute columns named a_1,a_2,....
By default, it is assumed that the DataFrames are in the "generalized" form, meaning that the keys of the dictionary correspond to main concepts.
Source code in mitm_tooling/representation/intermediate/mitm_data.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 | |
as_generalized() -> Self
Generalizes the MITMData by concatenating all DataFrames with the same parent concept. For example, for a concept hierarchy like:
- observation
- measurement
- event
The DataFrames for measurement and event will be concatenated into the DataFrame for observation.
Source code in mitm_tooling/representation/intermediate/mitm_data.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
as_specialized() -> Self
Specializes the MITMData by splitting all DataFrames into their leaf concepts. For example, for a concept hierarchy like:
- observation
- measurement
- event
The DataFrame for observation will be split into measurement and event.
Source code in mitm_tooling/representation/intermediate/mitm_data.py
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 | |
StreamingConceptData
Bases: BaseModel
This model represents streamable data for a specific concept, including its DataFrame structure (empty df with just column names) and a list of iterators for chunks of instances.
The instance chunks are expected to be tuples of (DataFrame, list[HeaderEntry]) where the DataFrame contains the actual data and the list of HeaderEntry provides metadata about the occurring types.
The outer list of iterators allows for multiple streams of data for the same concept, particularly when constructing the stream ad-hoc without prior knowledge of the contained concepts, e.g., when adding types individually and out-of-order w.r.t. concepts.
Note: Streamed data is assumed to be readable once.
Source code in mitm_tooling/representation/intermediate/streaming_mitm_data.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
StreamingMITMData
Bases: Iterable[tuple[ConceptName, StreamingConceptData]], BaseModel
This model represents streamable MITM data as a collection of StreamingConceptData.
By default, it is assumed that the streams are in the "generalized" form, meaning that the keys of the dictionary correspond to main concepts.
Note: Streamed data is assumed to be readable once.
Source code in mitm_tooling/representation/intermediate/streaming_mitm_data.py
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 | |
Functionality for reading and writing CSV files of the intermediate representation.
read_data_file(source: DataSource, target_mitm: MITM | None = None, target_concept: ConceptName | None = None, normalize: bool = False) -> pd.DataFrame
Read a CSV file into a DataFrame, optionally reindexing the columns as expected
in the intermediate representation given the target_concept of the target_mitm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
a readable byte or text buffer, or a file path |
required |
target_mitm
|
MITM | None
|
the target MITM |
None
|
target_concept
|
ConceptName | None
|
the target concept |
None
|
normalize
|
bool
|
whether to reindex the columns as expected in the intermediate representation |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
the read |
Source code in mitm_tooling/representation/file/read.py
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 | |
read_header_file(source: DataSource, normalize: bool = False) -> pd.DataFrame
Read a CSV file into a DataFrame, optionally reindexing the columns as expected
in the intermediate representation of a header file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
a readable byte or text buffer, or a file path |
required |
normalize
|
bool
|
whether to reindex the columns as expected in the intermediate representation |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
the read |
Source code in mitm_tooling/representation/file/read.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
write_data_file(df: pd.DataFrame, sink: DataSink | None, append: bool = False) -> str | None
Write the DataFrame df to a CSV file. If sink is a FilePath, ensure the directory exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
the |
required |
sink
|
DataSink | None
|
a writable byte or text buffer, or a file path |
required |
append
|
bool
|
whether to include the column header row. It is skipped if |
False
|
Returns:
| Type | Description |
|---|---|
str | None
|
None, or a string of the CSV-formatted contents if |
Source code in mitm_tooling/representation/file/write.py
19 20 21 22 23 24 25 26 27 28 29 30 31 | |
write_header_file(df: pd.DataFrame, sink: DataSink | None) -> str | None
Write the DataFrame df to a CSV file. If sink is a FilePath, ensure the directory exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
the |
required |
sink
|
DataSink | None
|
a writable byte or text buffer, or a file path |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
None, or a string of the CSV-formatted contents if |
Source code in mitm_tooling/representation/file/write.py
6 7 8 9 10 11 12 13 14 15 16 | |
DataFrame
A normalized representation of MITM data via pandas data frames. It is most suitable for data analysis and visualization.
MITMDataFrameStream = Iterable[tuple[ConceptName, Iterable[tuple[TypeName, Iterable[pd.DataFrame]]]]]
module-attribute
A stream of MITM data frames, where the data is grouped by concept and type, and includes type information (e.g., attributes/columns) next to the data frames.
In contrast to StreamingMITMDataFrames, the type information (Header) is not known in advance.
MITMDataFrames
Bases: Iterable[tuple[ConceptName, dict[TypeName, DataFrame]]], BaseModel
This model represents normalized MITM Data as a collection of pandas DataFrames, hierarchically organized by concept and type. It is intended to be used for in-memory representation of normalized MITM Data, e.g., when feeding it into data science packages.
Source code in mitm_tooling/representation/df/mitm_dataframes.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
StreamingMITMDataFrames
Bases: Iterable[tuple[ConceptName, dict[TypeName, DataFrame]]], BaseModel
This model explicitly represents a stream of structured MITM Data via a collection of Iterables.
In contrast to the bare MITMDataFrameStream, only the instances are (potentially) streamed, not the type information.
Note: Streamed data is assumed to be readable once.
Source code in mitm_tooling/representation/df/streaming_mitm_dataframes.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 | |
Relational/SQL
A relational representation of MITM data via a collection of tables and views. It is most suitable for data storage and ETL-pipeline generation.
SQLRepresentationSchema
Bases: BaseModel
This model represents the SQL representation of a MITM data set via a collection of SQLAlchemy tables and views.
It is not serializable itself but can be generated from a Header object (i.e., pure type information).
Source code in mitm_tooling/representation/sql/common.py
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 | |
append_data(bind: AnyDBBind, gen_sql_rep_schema: Callable[[], SQLRepresentationSchema], gen_instances: Callable[[], TypedMITMDataFrameStream] = lambda: ()) -> SQLRepInsertionResult
Append a stream of MITM dataframes into a relational database, with tables (and views) defined by the given SQL representation schema. This assumes that the schema is already created. In particular, this implies that the instances to be inserted cannot be of any type not yet present in the schema.
Note that if this function is called with a bind of type Connection (as opposed to a Engine),
a manual commit is required after calling it to persist the changes.
Internally, all changes are performed within nested transactions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bind
|
AnyDBBind
|
a bind to the database to insert into |
required |
gen_sql_rep_schema
|
Callable[[], SQLRepresentationSchema]
|
a factory for the SQL representation schema to use |
required |
gen_instances
|
Callable[[], TypedMITMDataFrameStream]
|
a factory for a stream of (typed) instances to insert |
lambda: ()
|
Returns:
| Type | Description |
|---|---|
SQLRepInsertionResult
|
a summary of the inserted instances |
Source code in mitm_tooling/representation/sql/sql_mutation/interface.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
create_schema(bind: AnyDBBind, gen_sql_rep_schema: Callable[[], SQLRepresentationSchema]) -> None
Create the mitm database schema defined by the given SQL representation schema factory.
Note that if this function is called with a bind of type Connection (as opposed to a Engine),
a manual commit is required after calling it to persist the changes.
Internally, all changes are performed within nested transactions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bind
|
AnyDBBind
|
a bind to the database to insert into |
required |
gen_sql_rep_schema
|
Callable[[], SQLRepresentationSchema]
|
a factory for the SQL representation schema to use |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in mitm_tooling/representation/sql/sql_mutation/interface.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
drop_data(bind: AnyDBBind, gen_sql_rep_schema: Callable[[], SQLRepresentationSchema])
Drop all instances from all tables, using the given ´gen_sql_rep_schema`. This preserves the type tables and meta-tables themselves.
Note that if this function is called with a bind of type Connection (as opposed to a Engine),
a manual commit is required after calling it to persist the changes.
Internally, all changes are performed within nested transactions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bind
|
AnyDBBind
|
a bind to the database to insert into |
required |
gen_sql_rep_schema
|
Callable[[], SQLRepresentationSchema]
|
a factory for the SQL representation schema to use |
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in mitm_tooling/representation/sql/sql_mutation/interface.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
drop_schema(bind: AnyDBBind, gen_sql_rep_schema: Callable[[], SQLRepresentationSchema]) -> None
Drop the mitm database schema defined by the given SQL representation schema factory.
Note that if this function is called with a bind of type Connection (as opposed to a Engine),
a manual commit is required after calling it to persist the changes.
Internally, all changes are performed within nested transactions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bind
|
AnyDBBind
|
a bind to the database to insert into |
required |
gen_sql_rep_schema
|
Callable[[], SQLRepresentationSchema]
|
a factory for the SQL representation schema to use |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in mitm_tooling/representation/sql/sql_mutation/interface.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
drop_type_instances(bind: AnyDBBind, sql_rep_schema: SQLRepresentationSchema, types_to_drop: Iterable[tuple[ConceptName, TypeName]] | None = None) -> None
Drop all instances of the given types from the mitm database given by the sql_rep_schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bind
|
AnyDBBind
|
a bind to the database to insert into |
required |
sql_rep_schema
|
SQLRepresentationSchema
|
the SQL representation schema to use |
required |
types_to_drop
|
Iterable[tuple[ConceptName, TypeName]] | None
|
an iterable of (concept, type_name) tuples to drop instances of |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in mitm_tooling/representation/sql/sql_mutation/drop_instances.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
insert_data(bind: AnyDBBind, gen_header: Callable[[], Header], gen_sql_rep_schema: Callable[[Header], SQLRepresentationSchema] = lambda h: mk_sql_rep_schema(h), gen_instances: Callable[[], TypedMITMDataFrameStream] = lambda: ()) -> SQLRepInsertionResult
Insert a stream of MITM dataframes into a relational database, with tables (and views) defined by the given SQL representation schema. The schema is first created and then the data is inserted. Finally, the meta-tables are updated with the header information.
Note that if this function is called with a bind of type Connection (as opposed to a Engine),
a manual commit is required after calling it to persist the changes.
Internally, all changes are performed within nested transactions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bind
|
AnyDBBind
|
a bind to the database to insert into |
required |
gen_header
|
Callable[[], Header]
|
a factory for a header to use for the SQL representation schema |
required |
gen_sql_rep_schema
|
Callable[[Header], SQLRepresentationSchema]
|
a factory for the SQL representation schema to use |
lambda h: mk_sql_rep_schema(h)
|
gen_instances
|
Callable[[], TypedMITMDataFrameStream]
|
a factory for a stream of (typed) instances to insert |
lambda: ()
|
Returns:
| Type | Description |
|---|---|
SQLRepInsertionResult
|
a summary of the inserted instances |
Source code in mitm_tooling/representation/sql/sql_mutation/interface.py
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 | |
mk_sql_rep_schema(header: Header, target_schema: SchemaName | None = SQL_REPRESENTATION_DEFAULT_SCHEMA, skip_fk_constraints: bool = False, skip_views: bool = False, include_meta_tables: bool = True) -> SQLRepresentationSchema
Generate an SQLRepresentationSchema from a Header.
The canonical relational MITM representation requires the inclusion of the meta-tables and views.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
header
|
Header
|
the header to generate the schema from |
required |
target_schema
|
SchemaName | None
|
the name of the schema to create the tables in. By default, the |
SQL_REPRESENTATION_DEFAULT_SCHEMA
|
skip_fk_constraints
|
bool
|
whether to skip the generation of foreign key constraints. Defaults to False. FKs can be useful for some external tools, but they may make mutating the database more difficult. |
False
|
skip_views
|
bool
|
whether to skip the generation of views. Defaults to False. |
False
|
include_meta_tables
|
bool
|
whether to include the meta-tables. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
SQLRepresentationSchema
|
|
Source code in mitm_tooling/representation/sql/sql_representation/mitm_db_schema.py
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 | |
mutate_schema(bind: AnyDBBind, gen_current_header: Callable[[], Header], gen_target_header: Callable[[], Header], gen_current_sql_rep_schema: Callable[[Header], SQLRepresentationSchema] = lambda h: mk_sql_rep_schema(h), gen_target_sql_rep_schema: Callable[[Header], SQLRepresentationSchema] = lambda h: mk_sql_rep_schema(h)) -> None
Mutate the header of a mitm db (relational database in canonical mitm format) to a target header. Migrating the derived SQL representation schema entails the following steps:
- drop all views that depend on types from the current header
- drop all types from the current header
- migrate the existing tables to reflect type changes and create new tables for new types
- recreate all type-dependent views
- update the meta-tables with the new header information
Note that if this function is called with a bind of type Connection (as opposed to a Engine),
a manual commit is required after calling it to persist the changes.
Internally, all changes are performed within nested transactions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bind
|
AnyDBBind
|
a bind to the database to insert into |
required |
gen_current_header
|
Callable[[], Header]
|
a factory for creating the current header from which to migrate |
required |
gen_target_header
|
Callable[[], Header]
|
a factory for creating the target header to which to migrate |
required |
gen_current_sql_rep_schema
|
Callable[[Header], SQLRepresentationSchema]
|
a factory for creating the current SQL representation schema from the current header |
lambda h: mk_sql_rep_schema(h)
|
gen_target_sql_rep_schema
|
Callable[[Header], SQLRepresentationSchema]
|
a factory for creating the target SQL representation schema from the target header |
lambda h: mk_sql_rep_schema(h)
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in mitm_tooling/representation/sql/sql_mutation/interface.py
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 | |
MITM Data Transformation
DataFrame
exportable_to_mitm_dataframes_stream(source: AnyDBBind, exportable: Exportable, stream_data: bool = False) -> MITMDataFrameStream
Apply the Exportable to the source database to generate a structured stream of data frames.
See also: StreamingMITMDataFrames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
AnyDBBind
|
a bind to the database to query from |
required |
exportable
|
Exportable
|
the |
required |
stream_data
|
bool
|
whether to query the database in chunks or not |
False
|
Returns:
| Type | Description |
|---|---|
MITMDataFrameStream
|
a |
Source code in mitm_tooling/transformation/df/from_exportable.py
19 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 | |
exportable_to_typed_mitm_dataframes_stream(source: AnyDBBind, exportable: Exportable, stream_data: bool = False) -> TypedMITMDataFrameStream
Apply the Exportable to the source database to generate a structured stream of data frames that includes explicit type information.
See also: StreamingMITMDataFrames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
AnyDBBind
|
a bind to the database to query from |
required |
exportable
|
Exportable
|
the |
required |
stream_data
|
bool
|
whether to query the database in chunks or not |
False
|
Returns:
| Type | Description |
|---|---|
TypedMITMDataFrameStream
|
a |
Source code in mitm_tooling/transformation/df/from_exportable.py
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 | |
mitm_data_into_mitm_dataframes(mitm_data: MITMData) -> MITMDataFrames
Unpack a MITMData object into a MITMDataFrames object.
Source code in mitm_tooling/transformation/df/from_intermediate.py
69 70 71 72 73 74 75 76 77 | |
mitm_dataframes_into_mitm_data(mitm_dataframes: MITMDataFrames) -> MITMData
Convert a MITMDataFrames object into a MITMData object.
Source code in mitm_tooling/transformation/df/into_intermediate.py
67 68 69 70 71 72 73 74 75 76 77 78 | |
streaming_mitm_data_into_typed_mitm_dataframe_stream(streaming_mitm_data: StreamingMITMData) -> TypedMITMDataFrameStream
Incrementally unpack StreamingMITMData into a TypedMITMDataFrameStream.
Source code in mitm_tooling/transformation/df/from_intermediate.py
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 | |
streaming_mitm_dataframes_into_streaming_mitm_data(streaming_mitm_dataframes: StreamingMITMDataFrames) -> StreamingMITMData
Convert a StreamingMITMDataFrames object into a StreamingMITMData object.
Source code in mitm_tooling/transformation/df/into_intermediate.py
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 | |
Relational/SQL
append_data(bind: AnyDBBind, gen_sql_rep_schema: Callable[[], SQLRepresentationSchema], gen_instances: Callable[[], TypedMITMDataFrameStream] = lambda: ()) -> SQLRepInsertionResult
Append a stream of MITM dataframes into a relational database, with tables (and views) defined by the given SQL representation schema. This assumes that the schema is already created. In particular, this implies that the instances to be inserted cannot be of any type not yet present in the schema.
Note that if this function is called with a bind of type Connection (as opposed to a Engine),
a manual commit is required after calling it to persist the changes.
Internally, all changes are performed within nested transactions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bind
|
AnyDBBind
|
a bind to the database to insert into |
required |
gen_sql_rep_schema
|
Callable[[], SQLRepresentationSchema]
|
a factory for the SQL representation schema to use |
required |
gen_instances
|
Callable[[], TypedMITMDataFrameStream]
|
a factory for a stream of (typed) instances to insert |
lambda: ()
|
Returns:
| Type | Description |
|---|---|
SQLRepInsertionResult
|
a summary of the inserted instances |
Source code in mitm_tooling/representation/sql/sql_mutation/interface.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
append_exportable(target: AnyDBBind, source: AnyDBBind, exportable: Exportable, target_schema: SchemaName | None = None, stream_data: bool = False) -> SQLRepInsertionResult
Insert instances from the source database into the target database, using the ETL-pipeline defined by the Exportable.
In contrast to insert_exportable, this function assumes that the schema is already created.
As a first step, the SQLRepresentationSchema is derived from the Header of the target database.
Then, the data is queried from the source and is inserted into the target.
Depending on the stream_data parameter, the data is incrementally queried and then inserted in chunks or first fully loaded and then inserted.
See also append_data.
Source code in mitm_tooling/transformation/sql/into_sql.py
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 | |
db_engine_into_db_meta(engine: sa.Engine) -> DBMetaInfo
Introspect an SQLAlchemy engine and return a DBMetaInfo object.
Source code in mitm_tooling/transformation/sql/from_sql.py
8 9 10 11 12 13 | |
header_into_db_meta(header: Header, override_schema: str | None = None) -> DBMetaInfo
Derive a DBMetaInfo object from a Header by generating a SQLRepresentationSchema and calling sql_rep_schema_into_db_meta.
Source code in mitm_tooling/transformation/sql/from_intermediate.py
7 8 9 10 11 12 13 14 | |
insert_exportable(target: AnyDBBind, source: AnyDBBind, exportable: Exportable, target_schema: SchemaName | None = None, stream_data: bool = False) -> SQLRepInsertionResult
Insert instances from the source database into the target database, using the ETL-pipeline defined by the Exportable.
First, the database schema, including tables, as defined by the SQLRepresentationSchema is created on the target database.
Then, the data is queried from the source and is inserted into the target.
Depending on the stream_data parameter, the data is inserted in batches or all at once.
See also insert_data.
Source code in mitm_tooling/transformation/sql/into_sql.py
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 | |
insert_mitm_data(bind: EngineOrConnection, mitm_data: MITMData, schema_name: SchemaName | None = None) -> SQLRepInsertionResult
Insert MITMData instances into a relational database, using the given SQLRepresentationSchema.
The database schema, including tables, is first created via DDL, then the data is inserted via INSERT statements.
See also insert_data.
Source code in mitm_tooling/transformation/sql/into_sql.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
insert_mitm_dataframes(bind: EngineOrConnection, mitm_dataframes: MITMDataFrames, schema_name: SchemaName | None = None) -> SQLRepInsertionResult
Insert MITMDataFrames instances into a relational database, using the given SQLRepresentationSchema.
The database schema, including tables, is first created via DDL, then the data is inserted via INSERT statements.
See also insert_data.
Source code in mitm_tooling/transformation/sql/into_sql.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
mitm_data_into_db_meta(mitm_data: MITMData, override_schema: str | None = None) -> DBMetaInfo
Derive a DBMetaInfo object from MITMData by calling header_into_db_meta on the dataset header.
Source code in mitm_tooling/transformation/sql/from_intermediate.py
17 18 19 20 21 | |
mitm_db_into_header(bind: AnyDBBind, override_schema: SchemaName | None = None) -> Header | None
Assuming a database with a MITM representation, reads the type information from the meta-tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bind
|
AnyDBBind
|
a bind to a database |
required |
override_schema
|
SchemaName | None
|
the name of the schema in which the tables are located |
None
|
Returns:
| Type | Description |
|---|---|
Header | None
|
the type information, or None if it failed |
Source code in mitm_tooling/transformation/sql/into_intermediate.py
12 13 14 15 16 17 18 19 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 | |
mk_sqlite(mitm_data: MITMData, file_path: FilePath | None = ':memory:', autoclose: bool = True) -> sa.Engine
Insert mitm_data into a SQLite database. It is created if it does not exist. Uses insert_mitm_data.
Source code in mitm_tooling/transformation/sql/into_sql.py
119 120 121 122 123 124 125 126 127 128 | |
sql_rep_into_exportable(header: Header, sql_rep_schema: SQLRepresentationSchema) -> Exportable
Create an Exportable from a Header by binding the concepts and types to the tables specified in the SQLRepresentationSchema.
Source code in mitm_tooling/transformation/sql/into_exportable.py
11 12 13 14 15 16 17 18 19 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 | |
sql_rep_into_mappings(header: Header, sql_rep_schema: SQLRepresentationSchema) -> list[ConceptMapping]
Generate a list of ConceptMappings from a Header and SQLRepresentationSchema.
Can be used to create Mapping
Source code in mitm_tooling/transformation/sql/into_mappings.py
7 8 9 10 11 12 13 14 15 16 17 18 19 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 | |
sql_rep_schema_into_db_meta(sql_rep_schema: SQLRepresentationSchema, default_schema: str = SQL_REPRESENTATION_DEFAULT_SCHEMA) -> DBMetaInfo
Derive a DBMetaInfo object from an SQLRepresentationSchema.
Source code in mitm_tooling/transformation/sql/from_sql.py
16 17 18 19 20 21 22 | |
Superset Asset Definitions and Generation
MITM Data Extraction from Relational Databases
DB Introspection Models
Representations for metadata of relational databases.
DBMetaInfo
Bases: DBMetaInfoBase
This model represents the metadata of a relational database via a structured collection of table metadata.
It extends the base model with additional DB metadata, in particular a SQLAlchemy MetaData object.
It is therefore not serializable.
It can be derived from SQLAlchemy metadata such as a list of Tables or a MetaData object.
Source code in mitm_tooling/extraction/relational/data_models/db_meta.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
DBProbe
Bases: DBProbeBase
This model represents a probe of a relational database, via a structured collection of table probes.
It additionally holds structural information in the form of a full DBMetaInfo object.
It is therefore not serializable.
Source code in mitm_tooling/extraction/relational/data_models/db_probe.py
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 | |
TableMetaInfo
Bases: TableMetaInfoBase
This model represents the metadata of a table in a relational database.
It extends the base model with additional information about the source of the table, in particular a SQLAlchemy Table object and a Queryable.
It is therefore not serializable.
Source code in mitm_tooling/extraction/relational/data_models/db_meta.py
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 | |
VirtualDB
Bases: VirtualDBBase
This model represents a virtual database via a structured collection of virtual views. As it contains SQLAlchemy objects, it is not serializable.
It can be mutated by adding and removing virtual views.
Given a specific SQL dialect, it can also be compiled into a serializable CompiledVirtualDB, which in turn can be used as a VirtualDBCreation in a StandaloneDBMapping.
Source code in mitm_tooling/extraction/relational/data_models/virtual_view.py
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 | |
VirtualView
Bases: VirtualViewBase
This model represents a virtual view in a relational database, i.e., a selectable SQL query in combination with its column metadata. As it contains SQLAlchemy objects, it is not serializable.
Given a specific SQL dialect, it can also be compiled into a serializable CompiledVirtualView.
Source code in mitm_tooling/extraction/relational/data_models/virtual_view.py
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 | |
DB Introspection
SQL Transformations for ETL-Pipelines
Mapping SQL to MITM Concepts
Representations and supporting functionality for mappings of relational data to MITM concepts.
BoundExportable
Bases: BaseModel
An Exportable that is bound to a specific database connection.
Source code in mitm_tooling/extraction/relational/mapping/export.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
ConceptMapping
Bases: StaticValidableGroup, BaseModel
This model represents a mapping of a database table to a MITM concept. Specifically, it records how the columns in the table correspond to the ones required by the concept in the specified MITM.
Given database schema information, it can be validated and produce a SQL selectable source of instances of the concept (in the format of the intermediate representation).
Source code in mitm_tooling/extraction/relational/mapping/concept_mapping.py
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 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
DBMapping
Bases: BaseModel
This model bundles a collection of ConceptMappings of individual tables.
Source code in mitm_tooling/extraction/relational/mapping/db_mapping.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
DataProvider
Bases: BaseModel
This model represents a data provider for instances and types of a MITM concept.
Source code in mitm_tooling/extraction/relational/mapping/concept_mapping.py
132 133 134 135 136 137 138 139 140 141 | |
Exportable
Bases: BaseModel
This model represents an ETL export of (mapped) MITM data from a relational database.
The data_providers attribute is a dictionary mapping concept names to lists of DataProviders.
A DataProvider represents a source of instances for a specific concept in the form a VirtualView, a post-processing pipeline, and a HeaderEntryProvider.
The Exportable is not bound to a specific database connection but rather represents an ETL pipeline from a relational DB to MITM Data.
By providing a bind to a database, it can be used to generate MITMData and StreamingMITMData, or be exported to a zip file. (also in a fully streamed fashion)
The header data can also be generated without necessarily querying all the instances.
In contrast to StreamingMITMData, the Exportable is expected to be reusable, i.e., its data sources are not read-once.
Note:
This model is not serializable as it contains VirtualViews which contain SQLAlchemy objects.
Essentially, it is indirectly bound to specific database metadata.
Consider StandaloneDBMapping for a serializable representation that can be turned into an Exportable.
Source code in mitm_tooling/extraction/relational/mapping/export.py
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 | |
HeaderEntry
Bases: BaseModel
This (immutable) model represents a single entry in a Header, i.e., a type definition.
Source code in mitm_tooling/representation/intermediate/header.py
19 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 | |
MappingExport
Bases: BaseModel
This model represents a mapping of relational data to MITM data, including optional post processing. It is used as an intermediate representation for an ETL pipeline that is yet to be bound to specific database metadata.
Source code in mitm_tooling/extraction/relational/mapping/export.py
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 | |
StandaloneDBMapping
Bases: DBMapping
This model extends a DBMapping with a VirtualDBCreation to create a standalone DBMapping.
The concept_mappings can refer to tables in the original DB or the virtual DB defined by the VirtualDBCreation.
A StandaloneDBMapping is serializable and intended to be used as an exchangeable ETL pipeline representation.
By providing an SQLAlchemy Engine, it can be turned into an ExecutableDBMapping or directly into an Exportable.
Source code in mitm_tooling/extraction/relational/mapping/db_mapping.py
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 | |
MITM Data Extraction from Files/DataFrames
ConvContext
A basic conversion context.
It supports conversion operations on the bound Engine.
Source code in mitm_tooling/extraction/anything/conversion_context.py
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 | |
apply_db_mapping(db_mapping: StandaloneDBMapping) -> BoundExportable
Apply a StandaloneDBMapping to the bound Engine, returning a BoundExportable.
It can be used to initiate a (streamed) export.
See Exportable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_mapping
|
StandaloneDBMapping
|
the |
required |
Returns:
| Type | Description |
|---|---|
BoundExportable
|
|
Source code in mitm_tooling/extraction/anything/conversion_context.py
200 201 202 203 204 205 206 207 208 209 210 211 | |
gen_llm_context(mitm: MITM, folder_path: FilePath | None = None) -> dict[str, str]
Generate, and optionally save, some textual context for an LLM to use for suggesting a StandaloneDBMapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mitm
|
MITM
|
the target MITM |
required |
folder_path
|
FilePath | None
|
optionally, a folder to save the context files to |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
a dictionary mapping file names to file contents |
Source code in mitm_tooling/extraction/anything/conversion_context.py
224 225 226 227 228 229 230 231 232 233 234 235 236 | |
probe() -> DBProbe
Probe the database using the bound Engine.
It contains information about the database schema and some sample-based inference of column types and value summaries.
See DBProbe.
Returns:
| Type | Description |
|---|---|
DBProbe
|
the probe result |
Source code in mitm_tooling/extraction/anything/conversion_context.py
213 214 215 216 217 218 219 220 221 222 | |
MutatingConvContext
Bases: ConvContext
A conversion context that allows mutating operations, e.g., importing DataFrames into the database.
See ConvContext.
Source code in mitm_tooling/extraction/anything/conversion_context.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
add_dfs(df_loaders: dict[str, Callable[[], pd.DataFrame]]) -> list[tuple[TableName, int]]
Insert the DataFrames provided by the df_loaders into the database using the bound Engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_loaders
|
dict[str, Callable[[], DataFrame]]
|
a mapping of table names to callables that return |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[TableName, int]]
|
some information about the inserted tables |
Source code in mitm_tooling/extraction/anything/conversion_context.py
248 249 250 251 252 253 254 255 256 257 | |
external_conv_ctxt(sql_alchemy_url: str | AnyUrl) -> Generator[ConvContext, None, None]
A conversion context that uses an external SQLAlchemy engine.
It does not support mutating operations (e.g., adding DataFrames).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql_alchemy_url
|
str | AnyUrl
|
the SQLAlchemy connection URL of the external database |
required |
Returns:
| Type | Description |
|---|---|
Generator[ConvContext, None, None]
|
|
Source code in mitm_tooling/extraction/anything/conversion_context.py
280 281 282 283 284 285 286 287 288 289 290 | |
local_conv_ctxt(variant: Literal['memory', 'tempdir'] = 'memory') -> Generator[MutatingConvContext, None, None]
A conversion context that uses a transient local SQLAlchemy engine. Can be either in-memory or on disk (in a temporary directory).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variant
|
Literal['memory', 'tempdir']
|
the variant of the local SQLite DB to use, either 'memory' or 'tempdir' |
'memory'
|
Returns:
| Type | Description |
|---|---|
Generator[MutatingConvContext, None, None]
|
|
Source code in mitm_tooling/extraction/anything/conversion_context.py
267 268 269 270 271 272 273 274 275 276 277 | |