Skip to main content

eqlpy

eqlpy is a Python package designed to facilitate interaction with the Encrypt Query Language (EQL). It provides classes and methods to encode and decode values when working with encrypted data in a PostgreSQL database.

Table of contents

Features

  • Data type handling: Supports various data types including integers, booleans, dates, floats, text, and JSONB.
  • Database formatting: Converts Python data types to the format required by EQL for database operations.
  • Parsing and reconstruction: Parses and reconstructs data from the database back into Python types.

Supported database packages

Currently, eqlpy supports either of the following database packages:

  • psycopg 3
  • sqlalchemy + psycopg 2

For code examples of storing and querying encrypted data with CipherStash Proxy using those packages, refer to examples directory and integration tests.

Installation

To install eqlpy, use the following command:

pip install eqlpy

You can find the latest version on the Python Package Index (PyPI).

Usage

Importing the package

from eqlpy import (
    EqlInt,
    EqlBool,
    EqlDate,
    EqlFloat,
    EqlText,
    EqlJsonb,
    EqlRow
)

EQL value classes

Each EQL value class inherits from the base EqlValue class and handles specific data types.

EqlInt

Handles integer values.

eql_int = EqlInt(42, 'users', 'age')
db_format = eql_int.to_db_format()
print(db_format)

EqlBool

Handles boolean values.

eql_bool = EqlBool(True, 'users', 'is_active')
db_format = eql_bool.to_db_format()
print(db_format)

EqlDate

Handles date values.

from datetime import date

eql_date = EqlDate(date.today(), 'users', 'created_at')
db_format = eql_date.to_db_format()
print(db_format)

EqlFloat

Handles floating-point values.

eql_float = EqlFloat(3.14, 'measurements', 'value')
db_format = eql_float.to_db_format()
print(db_format)

EqlText

Handles text values.

eql_text = EqlText('Hello, World!', 'messages', 'content')
db_format = eql_text.to_db_format()
print(db_format)

EqlJsonb

Handles JSONB values.

eql_jsonb = EqlJsonb({'key': 'value'}, 'configs', 'data')
db_format = eql_jsonb.to_db_format()
print(db_format)

Parsing values from database format

Use the from_parsed_json method to convert database-formatted JSON back to Python types.

import json

db_data = '{"k": "pt", "p": "42", "i": {"t": "users", "c": "age"}, "v": 1, "q": null}'
parsed = json.loads(db_data)
value = EqlInt.from_parsed_json(parsed)
print(value)  # Output: 42

EqlRow class

EqlRow maps database rows to Python objects using a column_function_map to process each column.

from datetime import datetime

row = {
    'id': '1',
    'age': '42',
    'is_active': 'true',
    'created_at': '2021-01-01',
    'value': '3.14',
    'content': 'Hello, World!',
    'data': '{"key": "value"}'
}

column_function_map = {
    'id': int,
    'age': int,
    'is_active': lambda x: x.lower() == 'true',
    'created_at': lambda x: datetime.fromisoformat(x).date(),
    'value': float,
    'data': json.loads
}

eql_row = EqlRow(column_function_map, row)
print(eql_row.row)

Output:

{
    'id': 1,
    'age': 42,
    'is_active': True,
    'created_at': datetime.date(2021, 1, 1),
    'value': 3.14,
    'content': 'Hello, World!',
    'data': {'key': 'value'}
}

Contributing

Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.

License

This project is licensed under the MIT License.

Metadata

Release files for eqlpy 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eqlpy 1.0.0
File Size Uploaded Provenance Actions
eqlpy-1.0.0.tar.gz 16.3 kB Without provenance Details for eqlpy-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for eqlpy 1.0.0
File Interpreter ABI Platform Actions
eqlpy-1.0.0-py3-none-any.whl Python 3 none any Details for eqlpy-1.0.0-py3-none-any.whl

Total release size: 21.7 kB

Release files / eqlpy-1.0.0.tar.gz

Download URL eqlpy-1.0.0.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2af3f40b1e96e1b6447c351225e1843233fab0f64d7af0e13f930319fdbe2821
BLAKE2b-256 checksum
How to use checksums
136878b3a06848db5552239c2e164e0094abdf7dad9a469170b3161c7e3e1836
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Release files / eqlpy-1.0.0-py3-none-any.whl

Download URL eqlpy-1.0.0-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0c588f20ac936f4208610526850482a6cdc301490fb490c2752b475e550e8e1
BLAKE2b-256 checksum
How to use checksums
75495ebb6a13f76150c3cc8304a529cf65b93669914953cfc84602981e112ca7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Security for eqlpy 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page