Skip to main content

EQL support library for Python 3

Project description

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.

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'}
}

Database interaction

For code examples of storing and querying with CipherStash Proxy, refer to examples directory

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eqlpy-0.0.3a12.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eqlpy-0.0.3a12-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file eqlpy-0.0.3a12.tar.gz.

File metadata

  • Download URL: eqlpy-0.0.3a12.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for eqlpy-0.0.3a12.tar.gz
Algorithm Hash digest
SHA256 2bca626c28e17fd0490d2e8ea02e29bec35e516d0a3594d575b387520049d670
MD5 af2fd658d6395161c8e8f1d2a811aef2
BLAKE2b-256 14336cea291f2e9671e5cbf47e17b706aea01934f676eedbbfeadfc9b06ca38c

See more details on using hashes here.

Provenance

The following attestation bundles were made for eqlpy-0.0.3a12.tar.gz:

Publisher: release-and-publish.yml on cipherstash/eqlpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file eqlpy-0.0.3a12-py3-none-any.whl.

File metadata

  • Download URL: eqlpy-0.0.3a12-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for eqlpy-0.0.3a12-py3-none-any.whl
Algorithm Hash digest
SHA256 072ea885ed4aaf4299d9a088c4b796b1d3f6dd5affd6517ed7fb9c4248a804d1
MD5 23e60ee4e0829e248f6f3aae814cd670
BLAKE2b-256 eba72d16f023606251ed50032f05ce2c37ee668a4da446a2fc62c6a99f7b0836

See more details on using hashes here.

Provenance

The following attestation bundles were made for eqlpy-0.0.3a12-py3-none-any.whl:

Publisher: release-and-publish.yml on cipherstash/eqlpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page