OTE-API Core Strategies¶
This page provides documentation for the oteapi.strategies
submodule, where all the core OTE-API strategies are located.
These strategies will always be available when setting up a server based on the OTE-API Core package.
download
¶
file
¶
Download strategy class for the file
scheme.
FileConfig
¶
Bases: AttrDict
File-specific Configuration Data Model.
Source code in oteapi/strategies/download/file.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
datacache_config: Optional[DataCacheConfig] = Field(None, description='Configurations for the data cache for storing the downloaded file content.')
class-attribute
instance-attribute
¶
encoding: Optional[str] = Field(None, description='Encoding used when opening the file. The default is platform dependent.')
class-attribute
instance-attribute
¶
text: bool = Field(False, description='Whether the file should be opened in text mode. If `False`, the file will be opened in bytes mode.')
class-attribute
instance-attribute
¶
FileResourceConfig
¶
Bases: ResourceConfig
File download strategy filter config.
Source code in oteapi/strategies/download/file.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
configuration: FileConfig = Field(FileConfig(), description='File download strategy-specific configuration.')
class-attribute
instance-attribute
¶
downloadUrl: FileUrl = Field(..., description='The file URL, which will be downloaded.')
class-attribute
instance-attribute
¶
ensure_path_exists(value)
¶
Ensure path
is defined in downloadUrl
.
Source code in oteapi/strategies/download/file.py
48 49 50 51 52 53 |
|
FileStrategy
¶
Strategy for retrieving data from a local file.
Registers strategies:
("scheme", "file")
Source code in oteapi/strategies/download/file.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 |
|
download_config: FileResourceConfig
instance-attribute
¶
get(session=None)
¶
Read local file.
Source code in oteapi/strategies/download/file.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
initialize(session=None)
¶
Initialize.
Source code in oteapi/strategies/download/file.py
74 75 76 |
|
SessionUpdateFile
¶
Bases: SessionUpdate
Class for returning values from Download File strategy.
Source code in oteapi/strategies/download/file.py
56 57 58 59 |
|
key: str = Field(..., description='Key to access the data in the cache.')
class-attribute
instance-attribute
¶
https
¶
Download strategy class for http/https
HTTPSConfig
¶
Bases: AttrDict
HTTP(S)-specific Configuration Data Model.
Source code in oteapi/strategies/download/https.py
16 17 18 19 20 21 22 |
|
datacache_config: Optional[DataCacheConfig] = Field(None, description='Configurations for the data cache for storing the downloaded file content.')
class-attribute
instance-attribute
¶
HTTPSResourceConfig
¶
Bases: ResourceConfig
HTTP(S) download strategy filter config.
Source code in oteapi/strategies/download/https.py
25 26 27 28 29 30 31 32 33 |
|
HTTPSStrategy
¶
Strategy for retrieving data via http.
Registers strategies:
("scheme", "http")
("scheme", "https")
Source code in oteapi/strategies/download/https.py
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 |
|
download_config: HTTPSResourceConfig
instance-attribute
¶
get(session=None)
¶
Download via http/https and store on local cache.
Source code in oteapi/strategies/download/https.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
initialize(session=None)
¶
Initialize.
Source code in oteapi/strategies/download/https.py
55 56 57 |
|
SessionUpdateHTTPS
¶
Bases: SessionUpdate
Class for returning values from Download HTTPS strategy.
Source code in oteapi/strategies/download/https.py
36 37 38 39 |
|
key: str = Field(..., description='Key to access the data in the cache.')
class-attribute
instance-attribute
¶
sftp
¶
Strategy class for sftp/ftp
AnyFtpUrl
¶
Bases: AnyUrl
A (S)FTP URL model.
Source code in oteapi/strategies/download/sftp.py
18 19 20 21 |
|
allowed_schemes = {'ftp', 'sftp'}
class-attribute
instance-attribute
¶
SFTPConfig
¶
Bases: AttrDict
(S)FTP-specific Configuration Data Model.
Source code in oteapi/strategies/download/sftp.py
24 25 26 27 28 29 30 |
|
datacache_config: Optional[DataCacheConfig] = Field(None, description='Configurations for the data cache for storing the downloaded file content.')
class-attribute
instance-attribute
¶
SFTPResourceConfig
¶
Bases: ResourceConfig
(S)FTP download strategy filter config.
Source code in oteapi/strategies/download/sftp.py
33 34 35 36 37 38 39 40 41 |
|
SFTPStrategy
¶
Strategy for retrieving data via sftp.
Registers strategies:
("scheme", "ftp")
("scheme", "sftp")
Source code in oteapi/strategies/download/sftp.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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
download_config: SFTPResourceConfig
instance-attribute
¶
get(session=None)
¶
Download via sftp
Source code in oteapi/strategies/download/sftp.py
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 |
|
initialize(session=None)
¶
Initialize.
Source code in oteapi/strategies/download/sftp.py
63 64 65 |
|
SessionUpdateSFTP
¶
Bases: SessionUpdate
Class for returning values from Download SFTP strategy.
Source code in oteapi/strategies/download/sftp.py
44 45 46 47 |
|
key: str = Field(..., description='Key to access the data in the cache.')
class-attribute
instance-attribute
¶
filter
¶
crop_filter
¶
Demo-filter strategy
CropImageConfig
¶
Bases: AttrDict
Configuration model for crop data.
Source code in oteapi/strategies/filter/crop_filter.py
14 15 16 17 18 19 |
|
crop: Tuple[int, int, int, int] = Field(..., description='Box cropping parameters (left, top, right, bottom).')
class-attribute
instance-attribute
¶
CropImageFilter
¶
Strategy for cropping an image.
Registers strategies:
("filterType", "filter/crop")
Source code in oteapi/strategies/filter/crop_filter.py
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 |
|
filter_config: CropImageFilterConfig
instance-attribute
¶
get(session=None)
¶
Execute strategy and return a dictionary
Source code in oteapi/strategies/filter/crop_filter.py
64 65 66 67 68 69 |
|
initialize(session=None)
¶
Initialize strategy and return a dictionary.
Source code in oteapi/strategies/filter/crop_filter.py
55 56 57 58 59 60 61 62 |
|
CropImageFilterConfig
¶
Bases: FilterConfig
Crop filter strategy filter config.
Source code in oteapi/strategies/filter/crop_filter.py
22 23 24 25 26 27 28 29 30 31 32 |
|
configuration: CropImageConfig = Field(..., description='Image crop filter strategy-specific configuration.')
class-attribute
instance-attribute
¶
filterType: str = Field('filter/crop', const=True, description=FilterConfig.__fields__['filterType'].field_info.description)
class-attribute
instance-attribute
¶
SessionUpdateCropFilter
¶
Bases: SessionUpdate
Return model for CropImageFilter
.
Source code in oteapi/strategies/filter/crop_filter.py
35 36 37 38 39 40 |
|
imagecrop: Tuple[int, int, int, int] = Field(..., description='Box cropping parameters (left, top, right, bottom).')
class-attribute
instance-attribute
¶
sql_query_filter
¶
SQL query filter strategy.
SQLQueryFilter
¶
Strategy for a SQL query filter.
Registers strategies:
("filterType", "filter/sql")
Source code in oteapi/strategies/filter/sql_query_filter.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
filter_config: SqlQueryFilterConfig
instance-attribute
¶
get(session=None)
¶
Execute strategy and return a dictionary.
Source code in oteapi/strategies/filter/sql_query_filter.py
50 51 52 |
|
initialize(session=None)
¶
Initialize strategy.
Source code in oteapi/strategies/filter/sql_query_filter.py
43 44 45 46 47 48 |
|
SessionUpdateSqlQuery
¶
Bases: SessionUpdate
Class for returning values from SQL Query data model.
Source code in oteapi/strategies/filter/sql_query_filter.py
25 26 27 28 |
|
sqlquery: str = Field(..., description='A SQL query string.')
class-attribute
instance-attribute
¶
SqlQueryFilterConfig
¶
Bases: FilterConfig
SQL query filter strategy filter config.
Source code in oteapi/strategies/filter/sql_query_filter.py
14 15 16 17 18 19 20 21 22 |
|
mapping
¶
mapping
¶
Mapping filter strategy.
MappingSessionUpdate
¶
Bases: SessionUpdate
SessionUpdate model for mappings.
Source code in oteapi/strategies/mapping/mapping.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
prefixes: Dict[str, str] = Field(..., description='Dictionary of shortnames that expands to an IRI given as local value/IRI-expansion-pairs.')
class-attribute
instance-attribute
¶
triples: List[RDFTriple] = Field(..., description='List of semantic triples given as (subject, predicate, object).')
class-attribute
instance-attribute
¶
MappingStrategy
¶
Strategy for a mapping.
The mapping strategy simply adds more prefixes and triples to the
prefixes
and triples
fields in the session such that they are
available for other strategies, like function strategies that convert
between data models.
Nothing is returned to avoid deleting existing mappings.
Registers strategies:
("mappingType", "triples")
Source code in oteapi/strategies/mapping/mapping.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 |
|
mapping_config: MappingConfig
instance-attribute
¶
get(session=None)
¶
Execute strategy and return a dictionary.
Source code in oteapi/strategies/mapping/mapping.py
62 63 64 |
|
initialize(session=None)
¶
Initialize strategy.
Source code in oteapi/strategies/mapping/mapping.py
48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
parse
¶
application_json
¶
Strategy class for application/json.
JSONConfig
¶
Bases: AttrDict
JSON parse-specific Configuration Data Model.
Source code in oteapi/strategies/parse/application_json.py
17 18 19 20 21 22 23 |
|
datacache_config: Optional[DataCacheConfig] = Field(None, description='Configurations for the data cache for storing the downloaded file content.')
class-attribute
instance-attribute
¶
JSONDataParseStrategy
¶
Parse strategy for JSON.
Registers strategies:
("mediaType", "application/json")
Source code in oteapi/strategies/parse/application_json.py
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 |
|
parse_config: JSONResourceConfig
instance-attribute
¶
get(session=None)
¶
Parse json.
Source code in oteapi/strategies/parse/application_json.py
61 62 63 64 65 66 67 68 69 70 |
|
initialize(session=None)
¶
Initialize.
Source code in oteapi/strategies/parse/application_json.py
57 58 59 |
|
JSONResourceConfig
¶
Bases: ResourceConfig
JSON parse strategy filter config.
Source code in oteapi/strategies/parse/application_json.py
26 27 28 29 30 31 32 33 34 35 36 |
|
configuration: JSONConfig = Field(JSONConfig(), description='JSON parse strategy-specific configuration.')
class-attribute
instance-attribute
¶
mediaType: str = Field('application/json', const=True, description=ResourceConfig.__fields__['mediaType'].field_info.description)
class-attribute
instance-attribute
¶
SessionUpdateJSONParse
¶
Bases: SessionUpdate
Class for returning values from JSON Parse.
Source code in oteapi/strategies/parse/application_json.py
39 40 41 42 |
|
content: dict = Field(..., description='Content of the JSON document.')
class-attribute
instance-attribute
¶
application_vnd_sqlite
¶
Strategy class for application/vnd.sqlite3.
SessionUpdateSqLiteParse
¶
Bases: SessionUpdate
Configuration model for SqLiteParse.
Source code in oteapi/strategies/parse/application_vnd_sqlite.py
62 63 64 65 |
|
result: list = Field(..., description='List of results from the query.')
class-attribute
instance-attribute
¶
SqliteParseConfig
¶
Bases: AttrDict
Configuration data model for
SqliteParseStrategy
.
Source code in oteapi/strategies/parse/application_vnd_sqlite.py
18 19 20 21 22 23 24 25 26 27 |
|
SqliteParseStrategy
¶
Parse strategy for SQLite.
Registers strategies:
("mediaType", "application/vnd.sqlite3")
Purpose of this strategy: Download a SQLite database using downloadUrl
and run a
SQL query on the database to return all relevant rows.
Source code in oteapi/strategies/parse/application_vnd_sqlite.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 104 105 106 107 108 109 110 111 112 113 114 |
|
parse_config: SqliteParserResourceConfig
instance-attribute
¶
get(session=None)
¶
Parse SQLite query responses.
Source code in oteapi/strategies/parse/application_vnd_sqlite.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
initialize(session=None)
¶
Initialize strategy.
Source code in oteapi/strategies/parse/application_vnd_sqlite.py
83 84 85 |
|
SqliteParserResourceConfig
¶
Bases: ResourceConfig
SQLite parse strategy resource config.
Source code in oteapi/strategies/parse/application_vnd_sqlite.py
30 31 32 33 34 35 36 37 38 39 40 |
|
configuration: SqliteParseConfig = Field(SqliteParseConfig(), description='SQLite parse strategy-specific configuration.')
class-attribute
instance-attribute
¶
mediaType: str = Field('application/vnd.sqlite3', const=True, description=ResourceConfig.__fields__['mediaType'].field_info.description)
class-attribute
instance-attribute
¶
create_connection(db_file)
¶
Create a database connection to SQLite database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_file |
Path
|
Full path to SQLite database file. |
required |
Raises:
Type | Description |
---|---|
Error
|
If a DB connection cannot be made. |
Returns:
Type | Description |
---|---|
Connection
|
Connection object. |
Source code in oteapi/strategies/parse/application_vnd_sqlite.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
excel_xlsx
¶
Strategy class for workbook/xlsx.
SessionUpdateXLSXParse
¶
Bases: SessionUpdate
Class for returning values from XLSXParse.
Source code in oteapi/strategies/parse/excel_xlsx.py
19 20 21 22 23 24 25 |
|
data: Dict[str, list] = Field(..., description='A dict with column-name/column-value pairs. The values are lists.')
class-attribute
instance-attribute
¶
XLSXParseConfig
¶
Bases: AttrDict
Data model for retrieving a rectangular section of an Excel sheet.
Source code in oteapi/strategies/parse/excel_xlsx.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 |
|
col_from: Optional[Union[int, str]] = Field(None, description='Excel column number or label of first column. Defaults to first assigned column.')
class-attribute
instance-attribute
¶
col_to: Optional[Union[int, str]] = Field(None, description='Excel column number or label of last column. Defaults to last assigned column.')
class-attribute
instance-attribute
¶
datacache_config: Optional[DataCacheConfig] = Field(None, description='Configurations for the data cache for retrieving the downloaded content.')
class-attribute
instance-attribute
¶
download_config: AttrDict = Field(AttrDict(), description='Configurations provided to a download strategy.')
class-attribute
instance-attribute
¶
header: Optional[List[str]] = Field(None, description='Optional list of column names, specifying the columns to return. These names they should match cells in `header_row`.')
class-attribute
instance-attribute
¶
header_row: Optional[int] = Field(None, description='Row number with the headers. Defaults to `1` if header is given, otherwise `None`.')
class-attribute
instance-attribute
¶
new_header: Optional[List[str]] = Field(None, description='Optional list of new column names replacing `header` in the output.')
class-attribute
instance-attribute
¶
row_from: Optional[int] = Field(None, description='Excel row number of first row. Defaults to first assigned row.')
class-attribute
instance-attribute
¶
row_to: Optional[int] = Field(None, description='Excel row number of last row. Defaults to last assigned row.')
class-attribute
instance-attribute
¶
worksheet: str = Field(..., description='Name of worksheet to load.')
class-attribute
instance-attribute
¶
XLSXParseParserConfig
¶
Bases: ParserConfig
XLSX parse strategy resource config.
Source code in oteapi/strategies/parse/excel_xlsx.py
83 84 85 86 87 88 89 90 91 92 93 |
|
configuration: XLSXParseConfig = Field(..., description='SQLite parse strategy-specific configuration.')
class-attribute
instance-attribute
¶
parserType: str = Field('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', const=True, description=ParserConfig.__fields__['parserType'].field_info.description)
class-attribute
instance-attribute
¶
XLSXParseStrategy
¶
Parse strategy for Excel XLSX files.
Registers strategies:
("parserType", "excel_xlsx")
Source code in oteapi/strategies/parse/excel_xlsx.py
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 |
|
parse_config: XLSXParseParserConfig
instance-attribute
¶
get(session=None)
¶
Parses selected region of an excel file.
Returns:
Type | Description |
---|---|
SessionUpdateXLSXParse
|
A dict with column-name/column-value pairs. The values are lists. |
Source code in oteapi/strategies/parse/excel_xlsx.py
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 |
|
initialize(session=None)
¶
Initialize.
Source code in oteapi/strategies/parse/excel_xlsx.py
165 166 167 |
|
get_column_indices(model, worksheet)
¶
Helper function returning a list of column indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
XLSXParseConfig
|
The parsed data model. |
required |
worksheet |
Worksheet
|
Excel worksheet, from which the header values will be retrieved. |
required |
Returns:
Type | Description |
---|---|
Iterable[int]
|
A list of column indices. |
Source code in oteapi/strategies/parse/excel_xlsx.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
set_model_defaults(model, worksheet)
¶
Update data model model
with default values obtained from worksheet
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
XLSXParseConfig
|
The parsed data model. |
required |
worksheet |
Worksheet
|
Excel worksheet, from which the default values will be obtained. |
required |
Source code in oteapi/strategies/parse/excel_xlsx.py
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 |
|
image
¶
Strategy class for image/jpg.
ImageDataParseStrategy
¶
Parse strategy for images.
This strategy uses Pillow to read a raw image from the data cache, converts it into a NumPy array and stores the new array in the data cache.
It also supports simple cropping and image conversions.
The key to the new array and other metadata is stored in the session. See
SessionUpdateImageParse
for more info.
Registers strategies:
("mediaType", "image/jpg")
("mediaType", "image/jpeg")
("mediaType", "image/jp2")
("mediaType", "image/png")
("mediaType", "image/gif")
("mediaType", "image/tiff")
("mediaType", "image/eps")
Source code in oteapi/strategies/parse/image.py
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 |
|
parse_config: ImageParserResourceConfig
instance-attribute
¶
get(session=None)
¶
Execute the strategy.
Source code in oteapi/strategies/parse/image.py
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 |
|
initialize(session=None)
¶
Initialize strategy.
Source code in oteapi/strategies/parse/image.py
145 146 147 |
|
ImageParserConfig
¶
Bases: AttrDict
Configuration data model for
ImageDataParseStrategy
.
Source code in oteapi/strategies/parse/image.py
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 |
|
crop: Optional[Tuple[int, int, int, int]] = Field(None, description='Box cropping parameters (left, top, right, bottom).')
class-attribute
instance-attribute
¶
datacache_config: Optional[DataCacheConfig] = Field(None, description='Configuration options for the local data cache.')
class-attribute
instance-attribute
¶
download_config: AttrDict = Field(AttrDict(), description='Configurations passed to the downloader.')
class-attribute
instance-attribute
¶
image_key: Optional[str] = Field(None, description='Key to use when storing the image data in datacache.')
class-attribute
instance-attribute
¶
image_mode: Optional[str] = Field(None, description='Pillow mode to convert image into. See https://pillow.readthedocs.io/en/stable/handbook/concepts.html for details.')
class-attribute
instance-attribute
¶
ImageParserResourceConfig
¶
Bases: ResourceConfig
Image parse strategy resource config.
Source code in oteapi/strategies/parse/image.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
configuration: ImageParserConfig = Field(ImageParserConfig(), description='Image parse strategy-specific configuration.')
class-attribute
instance-attribute
¶
mediaType: Literal['image/jpg', 'image/jpeg', 'image/jp2', 'image/png', 'image/gif', 'image/tiff', 'image/eps'] = Field(..., description=ResourceConfig.__fields__['mediaType'].field_info.description)
class-attribute
instance-attribute
¶
SessionUpdateImageParse
¶
Bases: SessionUpdate
Configuration model for ImageParse.
See Pillow handbook for more details
on image_mode
, image_palette
, and image_info
.
Source code in oteapi/strategies/parse/image.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 |
|
image_info: dict = Field({}, description='Additional information about the image.')
class-attribute
instance-attribute
¶
image_key: str = Field(..., description='Key with which the image content is stored in the data cache.')
class-attribute
instance-attribute
¶
image_mode: str = Field(..., description="Image mode. Examples: 'L', 'P', 'RGB', 'RGBA'...")
class-attribute
instance-attribute
¶
image_palette_key: Optional[str] = Field(None, description="Datacache key for colour palette if mode is 'P'.")
class-attribute
instance-attribute
¶
image_size: Tuple[int, int] = Field(..., description='Image size (width, height).')
class-attribute
instance-attribute
¶
SupportedFormat
¶
Bases: Enum
Supported formats for ImageDataParseStrategy
.
Source code in oteapi/strategies/parse/image.py
76 77 78 79 80 81 82 83 84 85 |
|
eps = 'EPS'
class-attribute
instance-attribute
¶
gif = 'GIF'
class-attribute
instance-attribute
¶
jp2 = 'JPEG2000'
class-attribute
instance-attribute
¶
jpeg = 'JPEG'
class-attribute
instance-attribute
¶
jpg = 'JPEG'
class-attribute
instance-attribute
¶
png = 'PNG'
class-attribute
instance-attribute
¶
tiff = 'TIFF'
class-attribute
instance-attribute
¶
postgres
¶
Strategy class for application/vnd.postgresql
PostgresConfig
¶
Bases: AttrDict
Configuration data model for
PostgresResourceStrategy
.
Source code in oteapi/strategies/parse/postgres.py
13 14 15 16 17 18 19 20 21 22 |
|
dbname: Optional[str] = Field(None, description='postgres dbname name')
class-attribute
instance-attribute
¶
password: Optional[str] = Field(None, description='postgres password')
class-attribute
instance-attribute
¶
sqlquery: Optional[str] = Field('', description='A SQL query string.')
class-attribute
instance-attribute
¶
user: Optional[str] = Field(None, description='postgres server username')
class-attribute
instance-attribute
¶
PostgresResourceConfig
¶
Bases: ResourceConfig
Postgresql parse strategy config
Source code in oteapi/strategies/parse/postgres.py
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 |
|
configuration: PostgresConfig = Field(PostgresConfig(), description='Configuration for resource. Values in the accessURL take precedence.')
class-attribute
instance-attribute
¶
datacache_config: Optional[DataCacheConfig] = Field(None, description='Configuration options for the local data cache.')
class-attribute
instance-attribute
¶
adjust_url(values)
¶
Root Validator Verifies configuration consistency, merge configurations and update the accessUrl property.
Source code in oteapi/strategies/parse/postgres.py
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 |
|
PostgresResourceStrategy
¶
Resource strategy for Postgres.
Registers strategies:
("accessService", "postgres")
Purpose of this strategy: Connect to a postgres DB and run a SQL query on the dbname to return all relevant rows.
Source code in oteapi/strategies/parse/postgres.py
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 |
|
resource_config: PostgresResourceConfig
instance-attribute
¶
get(session=None)
¶
Resource Postgres query responses.
Source code in oteapi/strategies/parse/postgres.py
158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
initialize(session=None)
¶
Initialize strategy.
Source code in oteapi/strategies/parse/postgres.py
154 155 156 |
|
SessionUpdatePostgresResource
¶
Bases: SessionUpdate
Configuration model for PostgresResource.
Source code in oteapi/strategies/parse/postgres.py
133 134 135 136 |
|
result: list = Field(..., description='List of results from the query.')
class-attribute
instance-attribute
¶
create_connection(resource_config)
¶
Create a dbname connection to Postgres dbname.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource_config |
PostgresResourceConfig
|
A dictionary providing everything needed for a psycopg connection configuration |
required |
Raises:
Type | Description |
---|---|
Error
|
If a DB connection cannot be made. |
Returns:
Type | Description |
---|---|
Connection
|
Connection object. |
Source code in oteapi/strategies/parse/postgres.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
text_csv
¶
Strategy class for text/csv.
CSVDialect: Type[Enum] = Enum(value='CSVDialect', names={dialect.upper(): dialectfor dialect in csv.list_dialects()}, module=__name__, type=str)
module-attribute
¶
CSV dialects.
All available dialects are retrieved through the csv.list_dialects()
function,
and will thus depend on the currently loaded and used Python interpreter.
CSVConfig
¶
Bases: AttrDict
CSV parse-specific Configuration Data Model.
Source code in oteapi/strategies/parse/text_csv.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
datacache_config: Optional[DataCacheConfig] = Field(None, description='Configurations for the data cache for storing the downloaded file content.')
class-attribute
instance-attribute
¶
dialect: DialectFormatting = Field(DialectFormatting(), description='Dialect and formatting parameters. See [the Python docs](https://docs.python.org/3/library/csv.html#csv-fmt-params) for more information.')
class-attribute
instance-attribute
¶
reader: ReaderConfig = Field(ReaderConfig(), description='CSV DictReader configuration parameters. See [the Python docs](https://docs.python.org/3/library/csv.html#csv.DictReader) for more information.')
class-attribute
instance-attribute
¶
CSVParseStrategy
¶
Parse strategy for CSV files.
Registers strategies:
("mediaType", "text/csv")
Source code in oteapi/strategies/parse/text_csv.py
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 |
|
parse_config: CSVResourceConfig
instance-attribute
¶
get(session=None)
¶
Parse CSV.
Source code in oteapi/strategies/parse/text_csv.py
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 |
|
initialize(session=None)
¶
Initialize.
Source code in oteapi/strategies/parse/text_csv.py
264 265 266 |
|
CSVResourceConfig
¶
Bases: ResourceConfig
CSV parse strategy filter config.
Source code in oteapi/strategies/parse/text_csv.py
231 232 233 234 235 236 237 238 239 240 241 |
|
DialectFormatting
¶
Bases: BaseModel
Dialect and formatting parameters for CSV.
See the Python docs for more information.
Note
As Dialect.lineterminator
is hardcoded in csv.reader
, it is left out of
this model.
Source code in oteapi/strategies/parse/text_csv.py
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 |
|
base: Optional[CSVDialect] = Field(None, description="A specific CSV dialect, e.g., 'excel'. Any other parameters here will overwrite the preset dialect parameters for the specified dialect.")
class-attribute
instance-attribute
¶
delimiter: Optional[str] = Field(None, description='A one-character string used to separate fields. See [the Python docs entry](https://docs.python.org/3/library/csv.html#csv.Dialect.delimiter) for more information.', min_length=1, max_length=1)
class-attribute
instance-attribute
¶
doublequote: Optional[bool] = Field(None, description='Controls how instances of [`quotechar`][oteapi.strategies.parse.text_csv.DialectFormatting.quotechar] appearing inside a field should themselves be quoted. When `True`, the character is doubled. When `False`, the [`escapechar`][oteapi.strategies.parse.text_csv.DialectFormatting.escapechar] is used as a prefix to the [`quotechar`][oteapi.strategies.parse.text_csv.DialectFormatting.quotechar]. See [the Python docs entry](https://docs.python.org/3/library/csv.html#csv.Dialect.doublequote) for more information.')
class-attribute
instance-attribute
¶
escapechar: Optional[str] = Field(None, description='A one-character string used by the writer to escape the [`delimiter`][oteapi.strategies.parse.text_csv.DialectFormatting.delimiter] if [`quoting`][oteapi.strategies.parse.text_csv.DialectFormatting.quoting] is set to [`QUOTE_NONE`][oteapi.strategies.parse.text_csv.QuoteConstants.QUOTE_NONE] and the [`quotechar`][oteapi.strategies.parse.text_csv.DialectFormatting.quotechar] if [`doublequote`][oteapi.strategies.parse.text_csv.DialectFormatting.doublequote] is `False`. On reading, the [`escapechar`][oteapi.strategies.parse.text_csv.DialectFormatting.escapechar] removes any special meaning from the following character. See [the Python docs entry](https://docs.python.org/3/library/csv.html#csv.Dialect.escapechar) for more information.', min_length=1, max_length=1)
class-attribute
instance-attribute
¶
quotechar: Optional[str] = Field(None, description='A one-character string used to quote fields containing special characters, such as the [`delimiter`][oteapi.strategies.parse.text_csv.DialectFormatting.delimiter] or [`quotechar`][oteapi.strategies.parse.text_csv.DialectFormatting.quotechar], or which contain new-line characters. See [the Python docs entry](https://docs.python.org/3/library/csv.html#csv.Dialect.quotechar) for more information.', min_length=1, max_length=1)
class-attribute
instance-attribute
¶
quoting: Optional[QuoteConstants] = Field(None, description='Controls when quotes should be generated by the writer and recognised by the reader. It can take on any of the `QUOTE_*` constants (see section [Module Contents](https://docs.python.org/3/library/csv.html#csv-contents)). See [the Python docs entry](https://docs.python.org/3/library/csv.html#csv.Dialect.quoting) for more information.')
class-attribute
instance-attribute
¶
skipinitialspace: Optional[bool] = Field(None, description='When `True`, whitespace immediately following the [`delimiter`][oteapi.strategies.parse.text_csv.DialectFormatting.delimiter] is ignored. See [the Python docs entry](https://docs.python.org/3/library/csv.html#csv.Dialect.skipinitialspace) for more information.')
class-attribute
instance-attribute
¶
strict: Optional[bool] = Field(None, description='When `True`, raise exception [Error](https://docs.python.org/3/library/csv.html#csv.Error) on bad CSV input. See [the Python docs entry](https://docs.python.org/3/library/csv.html#csv.Dialect.strict) for more information.')
class-attribute
instance-attribute
¶
validate_dialect_base(value)
¶
Ensure the given base
dialect is registered locally.
Source code in oteapi/strategies/parse/text_csv.py
157 158 159 160 161 162 163 164 165 |
|
QuoteConstants
¶
Bases: str
, Enum
CSV module QUOTE_*
constants.
Source code in oteapi/strategies/parse/text_csv.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
QUOTE_ALL = 'QUOTE_ALL'
class-attribute
instance-attribute
¶
QUOTE_MINIMAL = 'QUOTE_MINIMAL'
class-attribute
instance-attribute
¶
QUOTE_NONE = 'QUOTE_NONE'
class-attribute
instance-attribute
¶
QUOTE_NONUMERIC = 'QUOTE_NONNUMERIC'
class-attribute
instance-attribute
¶
csv_constant()
¶
Return the CSV lib equivalent constant.
Source code in oteapi/strategies/parse/text_csv.py
24 25 26 27 28 29 30 31 |
|
ReaderConfig
¶
Bases: BaseModel
CSV DictReader configuration parameters.
See the Python docs for more information.
Source code in oteapi/strategies/parse/text_csv.py
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 |
|
encoding: str = Field('utf8', description='The file encoding.')
class-attribute
instance-attribute
¶
fieldnames: Optional[list[str]] = Field(None, description='List of headers. If not set, the values in the first row of the CSV file will be used as the field names.')
class-attribute
instance-attribute
¶
restkey: Optional[Hashable] = Field(None, description='If a row has more fields than [`fieldnames`][oteapi.strategies.parse.text_csv.ReaderConfig.fieldnames], the remaining data is put in a list and stored with the field name specified by [`restkey`][oteapi.strategies.parse.text_csv.ReaderConfig.restkey].')
class-attribute
instance-attribute
¶
restval: Optional[Any] = Field(None, description='If a non-blank row has fewer fields than the length of [`fieldnames`][oteapi.strategies.parse.text_csv.ReaderConfig.fieldnames], the missing values are filled-in with the value of [`restval`][oteapi.strategies.parse.text_csv.ReaderConfig.restval].')
class-attribute
instance-attribute
¶
SessionUpdateCSVParse
¶
Bases: SessionUpdate
Class for returning values from CSV Parse.
Source code in oteapi/strategies/parse/text_csv.py
244 245 246 247 248 249 |
|
content: dict[Union[str, None], list[Any]] = Field(..., description='Content of the CSV document.')
class-attribute
instance-attribute
¶
resource
¶
transformation
¶
celery_remote
¶
Transformation Plugin that uses the Celery framework to call remote workers.
CELERY_APP = Celery(broker=f'redis://{REDIS_HOST}:{REDIS_PORT}', backend=f'redis://{REDIS_HOST}:{REDIS_PORT}')
module-attribute
¶
REDIS_HOST = os.getenv('OTEAPI_REDIS_HOST', 'redis')
module-attribute
¶
REDIS_PORT = int(os.getenv('OTEAPI_REDIS_PORT', '6379'))
module-attribute
¶
CeleryConfig
¶
Bases: AttrDict
Celery configuration.
All fields here (including those added from the session through the get()
method,
as well as those added "anonymously") will be used as keyword arguments to the
send_task()
method for the Celery App.
Note
Using alias
for the name
field to favor populating it with task_name
arguments, since this is the "original" field name. I.e., this is done for
backwards compatibility.
Setting allow_population_by_field_name=True
as pydantic model configuration in
order to allow populating it using name
as well as task_name
.
Source code in oteapi/strategies/transformation/celery_remote.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
CeleryRemoteStrategy
¶
Submit job to remote Celery runner.
Registers strategies:
("transformationType", "celery/remote")
Source code in oteapi/strategies/transformation/celery_remote.py
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 |
|
transformation_config: CeleryStrategyConfig
instance-attribute
¶
get(session=None)
¶
Run a job, return a job ID.
Source code in oteapi/strategies/transformation/celery_remote.py
85 86 87 88 89 90 91 92 93 |
|
initialize(session=None)
¶
Initialize a job.
Source code in oteapi/strategies/transformation/celery_remote.py
95 96 97 98 |
|
status(task_id)
¶
Get job status.
Source code in oteapi/strategies/transformation/celery_remote.py
100 101 102 103 |
|
CeleryStrategyConfig
¶
Bases: TransformationConfig
Celery strategy-specific configuration.
Source code in oteapi/strategies/transformation/celery_remote.py
58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
configuration: CeleryConfig = Field(..., description='Celery transformation strategy-specific configuration.')
class-attribute
instance-attribute
¶
transformationType: str = Field('celery/remote', const=True, description=TransformationConfig.__fields__['transformationType'].field_info.description)
class-attribute
instance-attribute
¶
SessionUpdateCelery
¶
Bases: SessionUpdate
Class for returning values from a Celery task.
Source code in oteapi/strategies/transformation/celery_remote.py
52 53 54 55 |
|