{"id":21492298,"url":"https://github.com/cipherstash/eqlpy","last_synced_at":"2025-10-25T15:39:05.243Z","repository":{"id":264110945,"uuid":"888290698","full_name":"cipherstash/eqlpy","owner":"cipherstash","description":"CipherStash EQL support library for Python3","archived":false,"fork":false,"pushed_at":"2024-12-25T03:15:06.000Z","size":143,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-09-25T10:56:23.987Z","etag":null,"topics":["data","data-security","encryption","postgresql","python"],"latest_commit_sha":null,"homepage":"https://github.com/cipherstash/encrypt-query-language","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cipherstash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-14T06:23:49.000Z","updated_at":"2025-01-12T18:31:14.000Z","dependencies_parsed_at":"2024-12-16T04:21:21.395Z","dependency_job_id":"9e3af64f-1cf4-4733-a54e-dcbbfd3d9031","html_url":"https://github.com/cipherstash/eqlpy","commit_stats":null,"previous_names":["cipherstash/eqlpy"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/cipherstash/eqlpy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Feqlpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Feqlpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Feqlpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Feqlpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cipherstash","download_url":"https://codeload.github.com/cipherstash/eqlpy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Feqlpy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000847,"owners_count":26082951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","data-security","encryption","postgresql","python"],"created_at":"2024-11-23T15:28:06.328Z","updated_at":"2025-10-09T06:41:57.398Z","avatar_url":"https://github.com/cipherstash.png","language":"Python","readme":"# EQLPY\n\n[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/cipherstash/eqlpy/python-app.yml?style=for-the-badge)](https://github.com/cipherstash/eqlpy/actions/workflows/python-app.yml)\n[![Built by CipherStash](https://raw.githubusercontent.com/cipherstash/meta/refs/heads/main/csbadge.svg)](https://cipherstash.com)\n\n [Website](https://cipherstash.com) | [GitHub](https://github.com/cipherstash/eqlpy) | [Reference](/reference/) | [Discussions](https://github.com/orgs/cipherstash/discussions)\n\n## Searchable encryption for Django and SQLAlchemy.\n\nBased on the CipherStash [Encrypt Query Language (EQL)](https://github.com/cipherstash/encrypt-query-language),`eqlpy` provides a simple, type-driven approach to enabling encryption in your application.\nBy using EQL's built-in searchable encryption schemes, your model queries retain **full** search capabilities, including exact lookups, range queries, ordering and free text search.\n\n## Table of contents\n\n- [Features](#features)\n- [Supported database packages](#supported-database-packages)\n- [Installation and Setup](#installation-and-setup)\n- [Usage with Django](#usage-with-django)\n  - [Defining an encrypted field](#defining-an-encrypted-field)\n  - [Inserting data](#inserting-data)\n  - [Queries](#queries)\n- [Migrating to EQLPY](#migrating-to-eqlpy)\n- [Contributing](#contributing)\n- [License](#license)\n- [Contact](#contact)\n\n## Features\n\n- **Data type handling**: Supports various data types including integers, booleans, dates, floats, text, and JSONB.\n- **Encrypted Search operations**: Search over encrypted data with no noticeable overhead.\n- **Standard API**: Includes adapters for Django and SQLAlchemy.\n- **Fast!**: Typical queries only incur a few milliseconds of overhead.\n\n## Supported database packages\n\nCurrently, eqlpy supports either of the following database packages:\n\n* psycopg 3 or psycopg 2\n* sqlalchemy + psycopg 2\n* Django + psycopg 2\n\nFor code examples of storing and querying encrypted data with [CipherStash Proxy](https://cipherstash.com/docs/getting-started/cipherstash-proxy) using those packages, refer to [examples directory](examples/) and [integration tests](tests/integration/).\n\n\n## Installation and Setup\n\n### Pre-requistites\n\nTo use `eqlpy` in your application, you will first need the following:\n\n* CipherStash Proxy connected to the target database\n* A ZeroKMS instance - which you can get via CipherStash Cloud\n* EQL installed in your database\n\n### Installation\n\nTo install `eqlpy`, use the following command:\n\n```bash\npip install eqlpy\n```\n\nYou can find the latest version on the [Python Package Index (PyPI)](https://pypi.org/project/eqlpy).\n\n## Usage with Django\n\n### Defining an encrypted field\n\nLet's say you have a customer model with an encrypted `name` field.\nYou can use the `EncryptedText` type when defining the field in the model:\n\n```python\nfrom django.db import models\nfrom eqlpy.eqldjango import *\n\nclass Customer(models.Model):\n    name = EncryptedText()\n```\n\nThe above customer model would create a database table like this:\n\n```sql\nCREATE TABLE myapp_customer (\n    \"id\" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,\n    \"name\" cs_encrypted_v1 NOT NULL,\n);\n```\n\n[!NOTE]\nThe column type in the database is `cs_encrypted_v1` which is encrypted type defined in [EQL](https://github.com/cipherstash/encrypt-query-language/blob/main/docs/reference/PAYLOAD.md). Internally EQL uses JSON.\n\n`eqlpy` supports many different data types, including numbers, dates and JSON.\nSee the [Reference](#) docs for more information.\n\nTODO: Link to the reference docs.\n\n### EQL Configuration\n\nEQL has a built in configuration system that manages encrypted state as well as any _Searchable Encrypted Metadata_ used to enable queries over encrypted records.\nEQL configurations are always **pending** until they are explicitly activated so its possible to batch several changes together.\n\nTo specify that the `name` column of our customer model should be encrypted we can call:\n\n```sql\nSELECT cs_add_column_v1('myapp_customer', 'name');\n```\n\nTo activate the pending configuration call:\n\n```sql\nSELECT cs_activate_v1();\n```\n\nIn Django, these changes can be managed using [Data Migrations](https://docs.djangoproject.com/en/5.1/topics/migrations/#data-migrations).\n\nFor example:\n\n```python\n# Generated by Django A.B on YYYY-MM-DD HH:MM\nfrom django.db import migrations\n\nclass Migration(migrations.Migration):\n  dependencies = [\n    (\"myapp\", \"0001_initial\"),\n  ]\n\n  operations = [\n    migrations.RunSQL(\"SELECT cs_add_column_v1('myapp_customer', 'name')\"),\n    migrations.RunSQL(\"SELECT cs_activate_v1()\")\n  ]\n```\n\nSee the [EQL Docs](https://github.com/cipherstash/encrypt-query-language/tree/main) for more information.\n\n### Inserting data\n\n`eqlpy` automatically encrypts values when saving to the database.\nYou can interact with the Django model in the same way as you normally would.\n\n```py\n\u003e\u003e\u003e customer = Customer(name=\"Fred Flintstone\")\n\u003e\u003e\u003e customer.save()\n```\n\nWhen retrieving a record, `eqlpy` automatically decrypts the value using the credentials defined in the setup step.\n\n```py\n\u003e\u003e\u003e customer = Customer.objects.get(customer.id)\n\u003e\u003e\u003e customer.name\n'Fred Flintstone'\n```\n\n#### View data in SQL\n\nViewing data in the database is possible via the proxy.\nQuery results will be automatically decrypted and returned in EQL form (JSON).\n\n```sql\nselect id, name from customers;\n```\n\n```\n  id  |                                        name                                      |\n -----+----------------------------------------------------------------------------------+\n  446 | {\"k\":\"pt\",\"p\":\"Fred Flintstone\",\"i\":{\"t\":\"customers\",\"c\":\"name\"},\"v\":1,\"q\":null} |\n```\n\nHowever, directly querying data via PostgreSQL will return the fully encrypted values.\n\n```\n id   | name |\n +---+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n 446 | {\"c\": \"mBbL^r9sYr{**CKA_6C{IDN*%A*Hh3Y^S6yIkF*Ez{m\u0026ib*gwg#*A)\u0026{F6mjUwBj_aVx|i6EsZUQXbrN)(~iOu-@!cWr+e^P~2NpGTB?trC@Gwq;6qtWxx\", \"i\": {\"c\": \"name\", \"t\": \"customers\"}, \"k\": \"ct\", \"m\": [], \"o\": null, \"u\": null, \"v\": 1} |\n```\n\n### Queries\n\nTo support queries on an encrypted column, an index must be added to the EQL configuration.\n\nTODO: This is **super** confusing.\nFor example, to allow simple _exact_ lookups of a given name an index with type `unique` must be added:\n\n```sql\nSELECT cs_add_index_v1('customers', 'name', 'unique');\n```\n\nAs before, this configuration is in a **pending** state until its activated.\nBecause our table already contains data, we can use the `cs_encrypt_v1` function to encrypt any existing records with the new config when activating.\nIn this case, we want to EQL to encrypt searchable encrypted metadata for the index we've just created.\n\n```sql\nSELECT cs_encrypt_v1();\nSELECT cs_activate_v1();\n```\n\nNow queries work much the same way in `eqlpy` as for Django - even though the data is fully encrypted!\n\nFor example, to find a record with a given name:\n\n```py\nCustomer.objects.get(name__eq=\"Alice Developer\")\n```\n\nText search works slightly differently.\nEQL doesn't define the `LIKE` operator, but instead uses an operator called `match` which works in a similar way but over encrypted values.\n\nWe can add a `match` index to the `name` field with EQL as follows:\n\n```sql\nSELECT cs_add_index_v1('customers', 'name', 'match');\nSELECT cs_encrypt_v1();\nSELECT cs_activate_v1();\n```\n\nNow the following query will work over encrypted data:\n\n```py\nfound = Customer.objects.get(name__match=\"caro\")\n```\n\nSee [Supported Queries](reference/SUPPORTED_QUERIES.md) for a full list of supported queries.\n\n## Migrating to EQLPY\n\nTODO\n\n```sql\nSELECT cs_encrypt_v1();\nSELECT cs_activate_v1();\n```\n\n\n## Release\n\nThis project has been set up to use [Trusted Publisher](https://docs.pypi.org/trusted-publishers/) in PyPI from GitHub Actions.\n\nTo make a GitHub release and publish to PyPI do the following steps:\n\n* Update the version in pyproject.toml in `main` branch (eg. \"1.2.3\")\n* Make a tag of the same version prefixed with \"v\" (eg. \"v1.2.3\"), and push\n  * `git tag v1.2.3`\n  * `git push v1.2.3`\n* `release-and-publish.yml` workflow will create a GitHub release, and publish the package to PyPI\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request on the [GitHub repository](https://github.com/cipherstash/eqlpy).\n\n## License\n\nThis project is licensed under the MIT License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcipherstash%2Feqlpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcipherstash%2Feqlpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcipherstash%2Feqlpy/lists"}