tableserializer.serializer module

Submodules

tableserializer.serializer.metadata module

class tableserializer.serializer.metadata.MetadataSerializer[source]

Bases: ABC, SignatureProvidingInstance

Serializer for table-related metadata objects. Defines a strategy for serializing the metadata contents in a specific way.

abstractmethod serialize_metadata(metadata: Dict[str, Any]) → str[source]

Serialize the given metadata.

Parameters:

metadata (Dict[str, Any]) – Metadata to serialize.

Returns:

String representation of the given metadata.

Return type:

str

class tableserializer.serializer.metadata.PairwiseMetadataSerializer[source]

Bases: MetadataSerializer

Metadata serializer that serializes entries in the metadata dictionary as “key: value” pairs.

serialize_metadata(metadata: Dict[str, Any]) → str[source]

Serialize the given metadata.

Parameters:

metadata (Dict[str, Any]) – Metadata to serialize.

Returns:

String representation of the given metadata.

Return type:

str

class tableserializer.serializer.metadata.JSONMetadataSerializer[source]

Bases: MetadataSerializer

Metadata serializer that serializes the full metadata dictionary as JSON.

serialize_metadata(metadata: Dict[str, Any]) → str[source]

Serialize the given metadata.

Parameters:

metadata (Dict[str, Any]) – Metadata to serialize.

Returns:

String representation of the given metadata.

Return type:

str

tableserializer.serializer.schema module

class tableserializer.serializer.schema.SchemaSerializer[source]

Bases: ABC, SignatureProvidingInstance

Serializer for the schema captured in the table.

abstractmethod serialize_schema(table: Table, metadata: Dict[str, Any] | None = None) → str[source]

Serialize the schema captured in the table.

Parameters:
  • table (Table) – The table whose schema should be serialized.

  • metadata (Optional[Dict[str, Any]]) – Optional metadata about the table.

Returns:

Serialized schema string.

Return type:

str

class tableserializer.serializer.schema.ColumnNameSchemaSerializer(column_name_separator: str = '|')[source]

Bases: SchemaSerializer

Schema serializer that serializes the schema as a separated list of column names.

Parameters:

column_name_separator (str) – Separator between column names.

serialize_schema(table: Table, metadata: Dict[str, Any] | None = None) → str[source]

Serialize the schema captured in the table.

Parameters:
  • table (Table) – The table whose schema should be serialized.

  • metadata (Optional[Dict[str, Any]]) – Optional metadata about the table.

Returns:

Serialized schema string.

Return type:

str

class tableserializer.serializer.schema.SQLSchemaSerializer(metadata_table_name_field: str | None = None, default_table_name: str = 'table')[source]

Bases: SchemaSerializer

Schema serializer that serializes the schema as a SQL CREATE TABLE statement.

Parameters:
  • metadata_table_name_field (Optional[str]) – Optional: Provide the name of the field in the metadata that specifies the table name.

  • default_table_name (str) – Default table name used in schema when no specific table name is available through the metadata.

serialize_schema(table: Table, metadata: Dict[str, Any] | None = None) → str[source]

Serialize the schema captured in the table.

Parameters:
  • table (Table) – The table whose schema should be serialized.

  • metadata (Optional[Dict[str, Any]]) – Optional metadata about the table.

Returns:

Serialized schema string.

Return type:

str

tableserializer.serializer.serializer module

class tableserializer.serializer.serializer.Serializer(recipe: SerializationRecipe, metadata_serializer: MetadataSerializer | None = None, schema_serializer: SchemaSerializer | None = None, table_serializer: RawTableSerializer | None = None, row_sampler: RowSampler | None = None, table_preprocessors: List[TablePreprocessor] | None = None)[source]

Bases: object

Serializer that serializes a given table according to a user-specified format.

Parameters:
  • recipe (SerializationRecipe) – The recipe detailing the serialization.

  • metadata_serializer (MetadataSerializer) – Serializer for the table metadata. Only needed if there is metadata placeholder in the recipe.

  • schema_serializer (SchemaSerializer) – Serializer for the table schema. Only needed if there is schema placeholder in the recipe.

  • table_serializer (RawTableSerializer) – Serializer for the raw table. Only needed if there is table placeholder in the recipe.

  • row_sampler (RowSampler) – Optional module that samples a number of rows from the raw table before serializing.

  • table_preprocessors (List[TablePreprocessor]) – Optional list of table preprocessors that transform the table before serialization.

serialize(table: List[Dict[str, str]] | DataFrame | List[List[str]], metadata: Dict[str, Any]) → str[source]

Serialize a given table.

Parameters:
  • table (Table) – Table to serialize.

  • metadata (Dict[str, Any]) – Metadata of the table to serialize.

Returns:

String serialization of the table.

Return type:

str

tableserializer.serializer.table module

class tableserializer.serializer.table.RawTableSerializer[source]

Bases: ABC, SignatureProvidingInstance

Serializer for serializing raw tables to string representations.

abstractmethod serialize_raw_table(table: Table) → str[source]

Serialize a raw table to string.

Parameters:

table (Table) – Raw table to serialize.

Returns:

Serialized raw table.

Return type:

str

class tableserializer.serializer.table.JSONRawTableSerializer[source]

Bases: RawTableSerializer

Serializer for serializing raw tables to row-wise JSON representations.

serialize_raw_table(table: Table) → str[source]

Serialize a raw table to string.

Parameters:

table (Table) – Raw table to serialize.

Returns:

Serialized raw table.

Return type:

str

class tableserializer.serializer.table.MarkdownRawTableSerializer[source]

Bases: RawTableSerializer

Serializer for serializing raw tables to markdown representations.

serialize_raw_table(table: Table) → str[source]

Serialize a raw table to string.

Parameters:

table (Table) – Raw table to serialize.

Returns:

Serialized raw table.

Return type:

str

class tableserializer.serializer.table.CSVRawTableSerializer(separator=',')[source]

Bases: RawTableSerializer

Serializer for serializing raw tables to csv representations.

Parameters:

separator (str) – Separator to use between values.

serialize_raw_table(table: Table) → str[source]

Serialize a raw table to string.

Parameters:

table (Table) – Raw table to serialize.

Returns:

Serialized raw table.

Return type:

str

class tableserializer.serializer.table.LatexRawTableSerializer[source]

Bases: RawTableSerializer

Serializer for serializing raw tables to LaTeX representations.

serialize_raw_table(table: Table) → str[source]

Serialize a raw table to string.

Parameters:

table (Table) – Raw table to serialize.

Returns:

Serialized raw table.

Return type:

str

Module contents