API Reference¶
Table Classes¶
Abstract Base¶
An SDMLTable. This is the abstract superclass for all Simple Data Markup Language tables, and
implements the schema methods of every SDML class. The data methods are implemented
by the concrete classes. Any new SDMLTable class should:
1. Subclass SDMLTable
2. Have a constructor with the argument schema
3. call super(<classname, self).init(schema) in the constructor
4. Implement the methods:
(a) all_values(self, column_name)
(b) range_spec(self, column_nam)
(c) _get_filtered_rows_from_filter(self, filter, columns = None)
(d) to_json(self)
where:
i. column_name is the name of the column to get the values/range_spec from
ii. filter is a an instance of SDQLFilter
iii. if columns is not None for get_filtered_rows, only return entries from those columns
in the result from get_filtered_rows
Arguments:
schema: a list of records of the form {"name": <column_name, "type":
Source code in src/sdtp/sdtp_table.py
140 141 142 143 144 145 146 147 148 |
|
all_values(column_name)
¶
get all the values from column_name Arguments: column_name: name of the column to get the values for
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
List of the values |
Source code in src/sdtp/sdtp_table.py
177 178 179 180 181 182 183 184 185 186 187 |
|
column_names()
¶
Return the names of the columns
Source code in src/sdtp/sdtp_table.py
151 152 153 154 155 |
|
column_types()
¶
Return the types of the columns
Source code in src/sdtp/sdtp_table.py
157 158 159 160 161 |
|
get_column(column_name)
¶
get the column column_name Arguments: column_name: name of the column to get
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
List of the values in the column |
Source code in src/sdtp/sdtp_table.py
189 190 191 192 193 194 195 196 197 198 199 200 |
|
get_column_type(column_name)
¶
Returns the type of column column_name, or None if this table doesn't have a column with name column_name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column_name
|
str
|
name of the column to get the type for |
required |
Source code in src/sdtp/sdtp_table.py
163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
get_filtered_rows(filter_spec=None, columns=None, format=DEFAULT_FILTERED_ROW_RESULT_FORMAT)
¶
Filter the rows according to the specific-ation given by filter_spec. Returns the rows for which the resulting filter returns True.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_spec
|
dict
|
Specification of the filter, as a dictionary |
None
|
columns
|
list
|
the names of the columns to return. Returns all columns if absent |
None
|
format
|
str
|
one of 'list', 'dict', 'sdml'. Default is list. |
DEFAULT_FILTERED_ROW_RESULT_FORMAT
|
Returns: list: The subset of self.get_rows() which pass the filter in the format specified by format
Source code in src/sdtp/sdtp_table.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
range_spec(column_name)
¶
Get the dictionary {min_val, max_val} for column_name Arguments:
column_name: name of the column to get the range spec for
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
the minimum and maximum of the column |
Source code in src/sdtp/sdtp_table.py
203 204 205 206 207 208 209 210 211 212 213 214 |
|
to_dictionary()
¶
Return the dictionary of this table, for saving on disk or transmission.
Source code in src/sdtp/sdtp_table.py
254 255 256 257 258 |
|
to_json()
¶
Return the JSON form of this table, for saving on disk or transmission.
Source code in src/sdtp/sdtp_table.py
260 261 262 263 264 265 266 267 |
|
Concrete Table Types¶
Bases: SDMLTable
A SDMLFixedTable: This is a convenience class for subclasses which generate a fixed number of rows locally, independent of filtering. This is instantiated with a function get_rows() which delivers the rows, rather than having them explicitly in the Table. Note that get_rows() must return a list of rows, each of which has the appropriate number of entries of the appropriate types. all_values, range_spec, and _get_filtered_rows_from_filter are all implemented on top of get_rows. Note that these methods can be overridden in a subclass if there is a more efficient method than the obvious implementation, which is what's implemented here.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema
|
List
|
a list of records of the form {"name": <column_name, "type": |
required |
get_rows
|
Callable
|
a function which returns a list of list of values. Each component list must have the same length as schema, and the jth element must be of the type specified in the jth element of schema |
required |
Source code in src/sdtp/sdtp_table.py
291 292 293 |
|
all_values(column_name)
¶
get all the values from column_name Arguments: column_name: name of the column to get the values for
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
List of the values |
Source code in src/sdtp/sdtp_table.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
check_column_type(column_name)
¶
For testing. Makes sure that all the entries in column_name are the right type No return, but throws an InvalidDataException if there's a bad element in the column
Source code in src/sdtp/sdtp_table.py
345 346 347 348 349 350 351 352 353 354 355 356 357 |
|
get_column(column_name)
¶
get all the column column_name Arguments: column_name: name of the column to get
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
The column as a list |
Source code in src/sdtp/sdtp_table.py
331 332 333 334 335 336 337 338 339 340 341 342 343 |
|
range_spec(column_name)
¶
Get the dictionary {min_val, max_val} for column_name Arguments: column_name: name of the column to get the range spec for
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
the minimum and maximum of the column |
Source code in src/sdtp/sdtp_table.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
to_dataframe()
¶
Convert the table to a PANDAS DataFrame. This is very straightforward; just use get_rows to get the rows and convert the schema to the appropriate dtypes. Note this relies on PANDAS type inference.
Source code in src/sdtp/sdtp_table.py
395 396 397 398 399 400 401 402 |
|
to_dictionary()
¶
Return the intermediate form of this table as a dictioary
Source code in src/sdtp/sdtp_table.py
404 405 406 407 408 409 410 411 412 |
|
Bases: SDMLFixedTable
A simple utility class to serve data from a static list of rows, which can be constructed from a CSV file, Excel File, etc. The idea is to make it easy for users to create and upload simple datasets to be served from a general-purpose server. Note that this will need some authentication.
Source code in src/sdtp/sdtp_table.py
513 514 515 516 517 518 519 520 |
|
Bases: SDMLTable
A SDTP Table on a remote server. This just has a schema, an URL, and header variables. This is the primary class for the client side of the SDTP, and in many packages would be a separate client module. However, the SDTP is designed so that Remote Tables can be used to serve local tables, so this is part of a server-side framework to. Parameters: table_name: name of the resmote stable schema: schema of the remote table url: url of the server hosting the remore table auth: dictionary of variables and values required to access the table Throws: InvalidDataException if the table doesn't exist on the server, the url is unreachable, the schema doesn't match the downloaded schema
Source code in src/sdtp/sdtp_table.py
616 617 618 619 620 621 622 623 624 |
|
all_values(column_name)
¶
get all the values from column_name Arguments:
column_name: name of the column to get the values for
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
List of the values |
Source code in src/sdtp/sdtp_table.py
727 728 729 730 731 732 733 734 735 736 737 738 |
|
connect_with_server()
¶
Connect with the server, ensuring that the server is: a. a SDTP server b. has self.table_name in its list of tables c. the table there has a matching schema
Source code in src/sdtp/sdtp_table.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
|
get_column(column_name)
¶
get the column column_name Arguments: column_name: name of the column to get
Returns:
Name | Type | Description |
---|---|---|
List |
list
|
The column as a list |
Source code in src/sdtp/sdtp_table.py
741 742 743 744 745 746 747 748 749 750 751 |
|
get_filtered_rows(filter_spec=None, columns=None, format=DEFAULT_FILTERED_ROW_RESULT_FORMAT)
¶
Filter the rows according to the specification given by filter_spec. Returns the rows for which the resulting filter returns True. Reorders columns to match client request, even if remote server responds in different order. This guarantees protocol safety.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_spec
|
dict
|
Specification of the filter, as a dictionary |
None
|
columns
|
list
|
the names of the columns to return. Returns all columns if absent |
None
|
format
|
str
|
one of 'list', 'dict', 'sdml'. Default is list. |
DEFAULT_FILTERED_ROW_RESULT_FORMAT
|
Returns: The subset of self.get_rows() which pass the filter in the format specified by format
Source code in src/sdtp/sdtp_table.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 |
|
range_spec(column_name)
¶
Get the dictionary {min_val, max_val} for column_name Arguments:
column_name: name of the column to get the range spec for
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
the minimum and maximum of the column |
Source code in src/sdtp/sdtp_table.py
754 755 756 757 758 759 760 761 762 763 764 765 |
|
Table Factories¶
Abstract Base¶
Bases: ABC
A class which builds an SDMLTable of a specific type. All SDMLTables have a schema, but after that the specification varies, depending on the method the table uses to get the table rows. Specific factories should subclass this and instantiate the class method build_table. The tag is the table type, simply a string which indicates which class of table should be built. A new SDMLTableFactory class should be built for each concrete subclass of SDMLTable, and ideally in the same file. The SDMLTable subclass should put a "type" field in the intermediate form, and the value of "type" should be the type built by the SDTP Table field SDMLTableFactory is an abstract class -- each concrete subclass should call the init method on the table_type on initialization. build_table is the method which actually builds the table; the superclass convenience version of the method throws an InvalidDataException if the spec has the wrong table type Every subclass should set the table_type. This attribute registers the tables which this Factory builds
check_table_type(table_type)
classmethod
¶
Check to make sure the type is right. If not, throw an InvalidDataException
Source code in src/sdtp/sdtp_table_factory.py
60 61 62 63 64 65 66 67 |
|
Concrete Factories¶
Bases: SDMLTableFactory
A factory to build RowTables -- in fact, all SDMLFixedTables. build_table is very simple, just instantiating a RowTable on the rows and schema of the specification
Bases: SDMLTableFactory
A factory to build RemoteSDMLTables. build_table is very simple, just instantiating a RemoteSDMLTables on the url and schema of the specification
Table Builder¶
A global table builder. This will build a table of any type. This has four methods, all class methods: (1) Build a table from a specification (2) register a class to build a table for a type (3) Get the current mapping of table types to classes (4) Get the class for a particular table type
build_table(spec, *args, **kwargs)
classmethod
¶
Build a table from a spec. Argments: spec: an SDML table spec args: additional arguments required to build the table, if any *kwargs: additional arguments required to build the table, if any Returns: The SDML Table Raises: Invalid Data Exception if the spec is not well-formed
Source code in src/sdtp/sdtp_table_factory.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
factory_class_registry()
classmethod
¶
Return the dictionary of table types to records (class, locked). Note it returns a COPY of the registry, so it can't be accidentally overwritten Arguments: None
Source code in src/sdtp/sdtp_table_factory.py
167 168 169 170 171 172 173 174 175 176 |
|
get_factory(table_type)
classmethod
¶
Get the class for table_type; return None if there is no class for tabletype Arguments: table_type: the type to get the class for Returns: the class which builds table_type, or None if there is no class Raises: None
Source code in src/sdtp/sdtp_table_factory.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
register_factory_class(table_type, factory_class, locked=False)
classmethod
¶
Register an SDMLTableFactory class to build tables of type table_type. If locked is True, then the SDMLTableFactory class can't be overriden by a subsequent register_factory_class invocation Arguments: table_type: the type of the table factory_class: the class to build it locked (default False): if True, the factory_class can't be overwritten Returns: None Raises: InvalidDataException if the type is already registered and locked, or if factory_class is not an SDMLFactoryClass
Source code in src/sdtp/sdtp_table_factory.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 |
|
Filtering¶
Abstract Base¶
Bases: BaseModel
Abstract base class for all filters.
to_filter_spec()
¶
Generate a dictionary form of the SDQLFilter. This is primarily for use on the client side, where A SDQLFilter can be constructed, and then a JSONified form of the dictionary version can be passed to the server for server-side filtering. It's also useful for testing and debugging Returns: A dictionary form of the Filter
Source code in src/sdtp/sdtp_filter.py
62 63 64 65 66 67 68 69 70 |
|
Atomic Filters¶
Bases: ColumnFilter
Implement an "IN_LIST" filter, which passes all rows in which the value of column is in the list given by values Arguments: values: list of values to check for
Bases: ColumnFilter
Implement a REGEX filter, which passes all rows in which the value of column matches the regular expression expression
Compound Filters¶
Bases: CompoundFilter
A None Filter -- matches a row if NONE of the arguments match on the column Arguments: arguments: set of subfilters
Utility Functions¶
Make a filter from a filter_spec. Note that filter_spec should be free of errors (run filter_spec_errors first) Arguments: filter_spec: A valid dictionary form of a filter Returns: An instance of SDQL Filters
Source code in src/sdtp/sdtp_filter.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
Method which checks to make sure that a filter spec is valid. Does not return, but throws an InvalidDataException with an error message if the filter spec is invalid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_spec
|
dict
|
spec to test for validity |
required |
Source code in src/sdtp/sdtp_filter.py
335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
Method which checks to make sure that a filter spec is valid. Returns True if and only if filter_spec has no errors
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_spec
|
dict
|
spec to test for validity |
required |
Source code in src/sdtp/sdtp_filter.py
350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
Filter Constants¶
Schema¶
SDML Type Constants¶
SDML Type Definitions¶
Schema Construction & Validation¶
Check to make sure that the Python type of val matches the implementation of sdml_type Arguments: sdml_type: an SDMLType () val: a Python value (can be anything)
Source code in src/sdtp/sdtp_schema.py
74 75 76 77 78 79 80 81 82 83 |
|
Given a list of tuples of the form (
Source code in src/sdtp/sdtp_schema.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
Returns True iff t is a valid SDML Type (["string", "number", "boolean", "date", "datetime", "timeofday"]) Argument: t: a string
Source code in src/sdtp/sdtp_schema.py
110 111 112 113 114 115 116 |
|
Validates that the given column dictionary includes required fields and a valid SDML type. Raises ValueError if invalid. Argument: col: a dictionary
Source code in src/sdtp/sdtp_schema.py
118 119 120 121 122 123 124 125 126 127 128 |
|
Validates a table schema dictionary against known SDML types and structure. Raises ValueError on failure.
Only 'schema' is allowed as the key for column definitions.
Source code in src/sdtp/sdtp_schema.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 |
|
Schema Structures¶
Bases: TypedDict
The base schema for a Table. A Table MUST have a type, which is a valid table, and a schema, which is a ColumnSpec list.
Bases: BaseTableSchema
The schema for a RowTable. The type of a RowTable is "RowTable", and it must have a "rows" field.
Bases: TypedDict
Specification of a Remote Authentication, for use with RemoteTables. It currently supports tokens, env variables, and files.
Bases: BaseTableSchema
The schema for a RemoteTable. The type of a RemoteTable is "RemoteSDMLTable", and it must have "url" and "table_name" fields. An auth field is optional.
Utilities¶
Exceptions¶
Bases: Exception
An exception thrown when a data table (list of rows) doesn't match an accoompanying schema, or a bad schema is specified, or a table row is the wrong length, or..
Source code in src/sdtp/sdtp_utils.py
69 70 71 |
|
Serialization Utilities¶
Source code in src/sdtp/sdtp_utils.py
36 37 38 39 40 41 |
|
Python doesn't jsonify dates, datetimes, or times properly, so convert them to isoformat strings. Return everything else as is Arguments: value -- the value to be converted column_type -- the SDTP type of the value Returns A jsonifiable form of the value
Source code in src/sdtp/sdtp_utils.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
IReturn the jsonified form of the row, using jsonifiable_value for each element Arguments: row -- the row to be converted column_types -- the types of each element of the row Returns A row of jsonifiable values
Source code in src/sdtp/sdtp_utils.py
90 91 92 93 94 95 96 97 98 99 |
|
Return the jsonifiable form of the list of rows, using jasonifiable_row for each row Arguments: rows -- the list of rows to be converted column_types -- the types of each element of the row Returns A list of rows of jsonified values
Source code in src/sdtp/sdtp_utils.py
102 103 104 105 106 107 108 109 110 111 |
|
Return a jsonifiable version of the column of values, using jsonifiable_value to do the conversion. We actually cheat a little, only calling _jsonifiable_value if column_type is one of SDML_TIME, "date", "datetime"
Source code in src/sdtp/sdtp_utils.py
114 115 116 117 118 119 120 121 122 123 |
|
Type Checking & Conversion¶
Check to make sure the values in list_of_values are all the right Python type for operations. Arguments: sdml_type: One of SDML_SCHEMA_TYPES list_of_values: a Python list to be tested
Source code in src/sdtp/sdtp_utils.py
45 46 47 48 49 50 51 52 53 54 |
|
Convert value to sdml_type, so that comparisons can be done. This is used to convert the values in a filter_spec to a form that can be used in a filter. Throws an InvalidDataException if the type can't be converted. An exception is Boolean, where "True, true, t" are all converted to True, but any other values are converted to False
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdml_type
|
str
|
type to convert to |
required |
value
|
Any
|
value to be converted |
required |
Returns: value cast to the correct type
Source code in src/sdtp/sdtp_utils.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 |
|
Convert value_list to sdml_type, so that comparisons can be done. Currently only works for lists of string, number, and boolean. Returns a default value if value can't be converted Note that it's the responsibility of the object which provides the rows to always provide the correct types, so this really should always just return a new copy of value_list Arguments: sdml_type: type to convert to value_list: list of values to be converted Returns: value_list with each element cast to the correct type
Source code in src/sdtp/sdtp_utils.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
Source code in src/sdtp/sdtp_utils.py
247 248 249 250 |
|
Convert the list of rows to the
Source code in src/sdtp/sdtp_utils.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
Convert value_dict to sdml_type, so that comparisons can be done. Currently only works for lists of string, number, and boolean.
Returns a default value if value can't be converted Note that it's the responsibility of the object which provides the rows to always provide the correct types, so this really should always just return a new copy of value_list Arguments: sdml_type: type to convert to value_dict: dictionary of values to be converted Returns: value_dict with each value in the dictionary cast to the correct type
Source code in src/sdtp/sdtp_utils.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
Authentication Utilities¶
Resolve an AuthMethod dict to a credential string. Returns None if the method can't be satisfied (env var/file missing, etc.).
Source code in src/sdtp/sdtp_utils.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
Table Server¶
Exceptions¶
Bases: Exception
An exception that is thrown when a table is not found in the TableServer
Source code in src/sdtp/table_server.py
62 63 |
|
Bases: Exception
An exception that is thrown when a column is not found for a specific table
Source code in src/sdtp/table_server.py
71 72 |
|
Table Server¶
The server for tables. Its task is to maintain a correspondence between table names and the actual tables. It also maintains the security information for a table (the variables and values required to access the table), and gives column information across tables
Source code in src/sdtp/table_server.py
94 95 96 97 98 99 100 101 |
|
add_sdtp_table(table_name, sdtp_table)
¶
Register a SDMLTable to serve data for a specific table name. Raises an InvalidDataException if table_name is None or sdtp_table is None or is not an instance of SDMLTable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table_name
|
str
|
name of the table |
required |
sdtp_table
|
SDMLTable
|
table to add |
required |
Source code in src/sdtp/table_server.py
129 130 131 132 133 134 135 136 137 138 139 140 |
|
add_sdtp_table_from_dictionary(name, table_dictionary)
¶
Add an SDMLTable from a dictionary (intermediate on-disk form). The table dictionary has fields schema and type, and then type- specific fields. Calls TableBuilder to build the table, then calls self.add_sdtp_table to add the table. Raises an InvalidDataException if self.add_sdtp_table or TableBuilder.buildTable raises it Arguments: name (str): the name of the table table_dictionary (dict): dictionary of the form {"type", "table"}, where table is a table specification: a dictionary with the fields type and schema
Source code in src/sdtp/table_server.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
get_all_tables()
¶
Get all the tables. This is to support a request for a numeric_spec or all_values for a column name when the table_name is not specified. In this case, all tables will be searched for this column name.
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
a list of all tables |
Source code in src/sdtp/table_server.py
161 162 163 164 165 166 167 168 169 170 171 172 |
|
get_all_values(table_name, column_name)
¶
Get all of the distinct values for column column_name for table table_name. Returns the list of distinct values for the columns Arguments: table_name (str): table to be searched column_name (str): name of the column
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
Returns the list of distinct values for the columns |
Raises: TableNotFoundException if the table is not found ColumnNotFoundException if the column can't be found
Source code in src/sdtp/table_server.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
get_column(table_name, column_name)
¶
Get the column for column column_name for table table_name. Returns the column as a list Arguments: table_name: table to be searched column_name: name of the column
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
Returns a dictionary with keys{max_val, min_val} |
Raises: TableNotFoundException if the table is not found ColumnNotFoundException if the column can't be found
Source code in src/sdtp/table_server.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
|
get_range_spec(table_name, column_name)
¶
Get the range specification for column column_name for table table_name. Returns a two-length list [min_val, max_val] Arguments: table_name: table to be searched column_name: name of the column
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
Returns a dictionary with keys{max_val, min_val} |
Raises: TableNotFoundException if the table is not found ColumnNotFoundException if the column can't be found
Source code in src/sdtp/table_server.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
get_table(table_name)
¶
Get the table with name table_name, first checking to see if table access is authorized by the passed headers. Arguments: table_name: name of the table to search for
Returns:
Name | Type | Description |
---|---|---|
SDMLTable |
SDMLTable
|
The SDML table corresponding to the request |
Raises: TableNotFoundException if the table is not found
Source code in src/sdtp/table_server.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
init_from_config(config_path)
¶
Initialize TableServer from config file. Config must be a JSON list as specified above.
Source code in src/sdtp/table_server.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
Table Loader Adapters¶
Bases: ABC
load()
abstractmethod
¶
Returns a dict spec for the table
Source code in src/sdtp/table_server.py
261 262 263 |
|
Bases: TableLoader
Loads a table from a path
Source code in src/sdtp/table_server.py
269 270 |
|
Bases: TableLoader
Source code in src/sdtp/table_server.py
278 279 280 |
|
Supports loading headers from file or env according to our spec: - {"from_file": "path/to/headers.json"} - {"headers": {"Authorization": {"from_env": "API_AUTH"}}}
Source code in src/sdtp/table_server.py
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 |
|
SDTP Web Server¶
The SDTPServer
blueprint exposes the following REST API endpoints:
/get_table_names
/get_tables
/get_table_schema
/get_filtered_rows
/get_range_spec
/get_all_values
/get_column
All endpoints return JSON; see the SDTP protocol docs for usage.
Flask Blueprint¶
Bases: Blueprint
An SDTP Server. This is just an overlay on a Flask Blueprint, added so we can expose initialize methods to the application
Source code in src/sdtp/sdtp_server.py
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 |
|
SDTP Client¶
Exceptions¶
Configuration¶
Loads and validates the SDTPClient YAML config file.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, AuthMethod] -- The credentials mapping (URL -> AuthMethod). |
Raises: Exception on parse or validation error.
Source code in src/sdtp/sdtp_client.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 |
|
Main Client¶
Minimal SDTP Client: Connects to SDTP REST endpoints with robust, flexible authentication.
Credential Discovery & Authentication¶
SDTPClient uses a YAML config file as a minimal password manager, mapping each SDTP server URL to a credential retrieval method:
env
: Get the credential from a named environment variable (supports ephemeral tokens from IdP or orchestration).path
: Read the credential from a file (works with secrets managers or file mounts).value
: Use the explicit token value (for dev/test only).
The config file is read at instantiation (default: ~/.sdtp_client_config.yaml
), and may be overridden by the SDTP_CLIENT_CONFIG
env var or config_path
argument.
For each API call
- If an explicit
auth
argument is supplied, it overrides all other methods for that call only. - Otherwise, the credential method for the client's server URL is looked up in the config file.
- If no entry is found for the URL, the 'default' entry (if any) is used.
- If no credential method is found, no Authorization header is sent (anonymous access).
All credential methods are re-evaluated at each call — changes to env vars or files are picked up automatically.
Power users may also specify headers
per method to override or add HTTP headers directly.
Convenience Methods¶
SDTPClient provides high-level helpers to build table schemas, filter specs, and DataFrames, minimizing boilerplate and making SDTP more accessible for data science and ETL workflows.
See the user documentation for full config format, method details, and best practices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
Base URL of the SDTP server (e.g., "http://localhost:5000") |
required |
config_path
|
Optional[str]
|
Optional path to the YAML credential config file (default: "~/.sdtp_client_config.yaml"). |
'~/.sdtp_client_config.yaml'
|
auth
|
Optional[AuthMethod]
|
Optional explicit AuthMethod for this client (overrides config). |
None
|
Source code in src/sdtp/sdtp_client.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
clear()
¶
Clear the stored credential method for this client. After calling, further calls will use config or explicit per-method auth.
Source code in src/sdtp/sdtp_client.py
134 135 136 137 138 139 |
|
echo_json_post(payload, auth=None)
¶
POST /_echo_json_post — Echoes posted JSON (debug/testing only).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
payload
|
dict
|
Payload in JSON form. |
required |
auth
|
Optional[Union[str, AuthMethod]]
|
Auth token or method for this request (overrides all others). |
None
|
Returns:
Type | Description |
---|---|
dict
|
The echoed payload (dict). |
Raises:
Type | Description |
---|---|
SDTPClientError
|
SDTPClientError on a bad response. |
Source code in src/sdtp/sdtp_client.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
|
get_all_values(table_name, column_name, auth=None)
¶
Returns all distinct values for a column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table_name
|
str
|
Table containing the column. |
required |
column_name
|
str
|
Column to get values for. |
required |
auth
|
Optional[Union[str, AuthMethod]]
|
Optional string token or AuthMethod dict for this call. |
None
|
Returns:
Type | Description |
---|---|
List[Any]
|
List[Any]: List of column values. |
Raises:
Type | Description |
---|---|
SDTPClientError
|
SDTPClientError on a bad response. |
Source code in src/sdtp/sdtp_client.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
get_column(table_name, column_name, auth=None)
¶
Returns the entire column as a list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table_name
|
str
|
Table containing the column. |
required |
column_name
|
str
|
Column to get. |
required |
auth
|
Optional[Union[str, AuthMethod]]
|
Optional string token or AuthMethod dict for this call. |
None
|
Returns:
Type | Description |
---|---|
List[Any]
|
List[Any]: The column as a list. |
Raises:
Type | Description |
---|---|
SDTPClientError
|
SDTPClientError on a bad response. |
Source code in src/sdtp/sdtp_client.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
|
get_filtered_rows(table, columns=None, filter=None, result_format=None, auth=None)
¶
POST /get_filtered_rows — Fetch filtered rows from a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
Name of the table (required). |
required |
columns
|
Optional[List[str]]
|
List of columns to return (optional). |
None
|
filter
|
Optional[Dict[str, Any]]
|
SDTP filter spec (optional). |
None
|
result_format
|
Optional[str]
|
Output format (optional). |
None
|
auth
|
Optional[Union[str, AuthMethod]]
|
Auth token or method for this request (overrides all others). |
None
|
Returns:
Type | Description |
---|---|
Any
|
List of rows (list of lists), or as specified by result_format. |
Raises:
Type | Description |
---|---|
SDTPClientError
|
SDTPClientError on a bad response. |
Source code in src/sdtp/sdtp_client.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
|
get_range_spec(table_name, column_name, auth=None)
¶
Returns [min, max] for a column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table_name
|
str
|
Table containing the column. |
required |
column_name
|
str
|
Column to get min/max for. |
required |
auth
|
Optional[Union[str, AuthMethod]]
|
Optional string token or AuthMethod dict for this call. |
None
|
Returns:
Type | Description |
---|---|
List[Any]
|
List[Any]: List of length 2: [min, max] |
Raises:
Type | Description |
---|---|
SDTPClientError
|
SDTPClientError on a bad response. |
Source code in src/sdtp/sdtp_client.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
|
get_table_schema(table_name, auth=None)
¶
Returns the schema for a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table_name
|
str
|
Table to get the schema for. |
required |
auth
|
Optional[Union[str, AuthMethod]]
|
Optional string token or AuthMethod dict for this call. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, str]]
|
List[Dict[str, str]]: Schema for the table. |
Raises:
Type | Description |
---|---|
SDTPClientError
|
SDTPClientError on a bad response. |
Source code in src/sdtp/sdtp_client.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
get_tables(auth=None)
¶
Returns a dictionary indexed by table name with values the schema for each table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
auth
|
Optional[Union[str, AuthMethod]]
|
Optional string token or AuthMethod dict to use for this call. |
None
|
Returns:
Type | Description |
---|---|
Dict[str, Dict]
|
Dict[Dict]: Dictionary of table schemas |
Raises:
Type | Description |
---|---|
SDTPClientError
|
SDTPClientError on a bad response. |
Source code in src/sdtp/sdtp_client.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
list_tables(auth=None)
¶
Returns a list of table names from the server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
auth
|
Optional[Union[str, AuthMethod]]
|
Optional string token or AuthMethod dict to use for this call. |
None
|
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: list of table names. |
Raises:
Type | Description |
---|---|
SDTPClientError
|
SDTPClientError on a bad response. |
Source code in src/sdtp/sdtp_client.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
query_credential_method(url=None)
¶
Return the authentication method (AuthMethod) for the specified URL, as stored in this client's credentials mapping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
Optional[str]
|
The server URL to query (defaults to this client's URL if None). |
None
|
Returns:
Type | Description |
---|---|
Optional[AuthMethod]
|
The AuthMethod dict (e.g., {'env': ...}, {'path': ...}, or {'value': ...}), |
Optional[AuthMethod]
|
or None if no method is configured for this URL. |
Example
method = client.query_credential_method()
returns this client's method¶
method = client.query_credential_method("https://other.example.com")
returns method for another URL (if in credentials)¶
Source code in src/sdtp/sdtp_client.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
table_exists(table_name, auth=None)
¶
Return True if and only if table table_name exists on the server Args: table_name: Table to check. auth: Optional string token or AuthMethod dict for this call. Returns: bool: True if the table exists, False otherwise.
Source code in src/sdtp/sdtp_client.py
441 442 443 444 445 446 447 448 449 450 451 |
|