polars.ParquetEncryptionProperties#

class polars.ParquetEncryptionProperties(
*,
footer_key: bytes,
column_keys: Mapping[str, bytes] | None = None,
plaintext_footer: bool = False,
aad_prefix: bytes | None = None,
store_aad_prefix: bool = False,
)[source]#

Properties for writing Parquet files encrypted with Parquet modular encryption.

Warning

This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.

Parameters:
footer_key

The key used to encrypt the file footer, or to sign the footer if plaintext_footer is set. If no column keys are specified, all columns are also encrypted with the footer key.

column_keys

Keys used to encrypt columns with column-specific keys, keyed by column name. If any column keys are specified, only the columns with a key are encrypted and all other columns are written unencrypted. For nested columns, the column name is the dot-separated path in the Parquet schema, e.g. a.b.c.

plaintext_footer

Write the file footer in plaintext rather than encrypting it, so that readers without the footer key can read the schema and any unencrypted columns. The footer is still signed with the footer key.

aad_prefix

The AAD (additional authenticated data) prefix. Readers that provide an AAD prefix can only read files written with the same prefix, which protects against a file being swapped for one written with a different prefix, such as an older version of the file. The same prefix is used for every file written by a single write_parquet or sink_parquet call, so it does not protect against swapping files written together when partitioning, or files from different calls that used the same prefix.

store_aad_prefix

Store the AAD prefix in the file. If this is false, readers must provide the AAD prefix in order to read the file.

Notes

The keys are stored unencrypted in the serialized query when a query that uses these properties is serialized, for example with LazyFrame.serialize(), by pickling a LazyFrame, or to run on Polars Nanook. Anyone who can read the serialized query can decrypt the files with these keys, so treat it as being as sensitive as the keys themselves. To avoid serializing keys, use ParquetEncryptionConfig and ParquetDecryptionConfig with a Key Management Service instead. These never serialize encryption keys, but do serialize the KMS key access token (see KmsConnectionConfig).

Examples

>>> encryption_properties = pl.ParquetEncryptionProperties(
...     footer_key=b"0123456789012345",
...     column_keys={"x": b"1234567890123450"},
... )
__init__(
*,
footer_key: bytes,
column_keys: Mapping[str, bytes] | None = None,
plaintext_footer: bool = False,
aad_prefix: bytes | None = None,
store_aad_prefix: bool = False,
) → None[source]#

Methods

__init__(*, footer_key[, column_keys, ...])