{"id":28317489,"url":"https://github.com/brake/peewee_encrypted_field","last_synced_at":"2026-05-07T05:32:17.353Z","repository":{"id":57451712,"uuid":"70525910","full_name":"brake/peewee_encrypted_field","owner":"brake","description":"Encrypted field to save your data as Fernet tokens","archived":false,"fork":false,"pushed_at":"2016-11-01T19:57:54.000Z","size":11,"stargazers_count":1,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-24T14:46:31.567Z","etag":null,"topics":["database","encryption","peewee","python"],"latest_commit_sha":null,"homepage":null,"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/brake.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-10T20:26:30.000Z","updated_at":"2017-10-16T21:52:04.000Z","dependencies_parsed_at":"2022-09-06T05:31:46.068Z","dependency_job_id":null,"html_url":"https://github.com/brake/peewee_encrypted_field","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/brake/peewee_encrypted_field","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brake%2Fpeewee_encrypted_field","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brake%2Fpeewee_encrypted_field/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brake%2Fpeewee_encrypted_field/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brake%2Fpeewee_encrypted_field/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brake","download_url":"https://codeload.github.com/brake/peewee_encrypted_field/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brake%2Fpeewee_encrypted_field/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32724491,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"ssl_error","status_checked_at":"2026-05-07T02:14:29.405Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["database","encryption","peewee","python"],"created_at":"2025-05-25T05:19:29.711Z","updated_at":"2026-05-07T05:32:17.348Z","avatar_url":"https://github.com/brake.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"######################\npeewee_encrypted_field\n######################\n\n.. image:: https://img.shields.io/badge/license-MIT-blue.svg?style=flat \n        :target: https://opensource.org/licenses/MIT \n        \n.. image:: https://badge.fury.io/gh/brake%2Fpeewee_encrypted_field.svg\n        :target: https://badge.fury.io/gh/brake%2Fpeewee_encrypted_field\n        \n.. image:: https://img.shields.io/badge/Python-2.7-red.svg\n\n.. _fernet-py: https://github.com/heroku/fernet-py\n.. _Fernet tokens:\n.. _fernet spec: https://github.com/fernet/spec\n.. _Pycrypto: https://pypi.python.org/pypi/pycrypto\n\nEncrypted field for `Peewee ORM \u003chttps://github.com/coleifer/peewee\u003e`_ models to save data in DB in encrypted form.\n\nData stored in DataBase as `Fernet tokens`_. After you define an encryption key all cryptography will be performed transparently for your application.\n\nUses simple fernet implementation https://github.com/heroku/fernet-py\n\nIdea caught from SQLAlchemy's `EncryptedType \u003chttp://sqlalchemy-utils.readthedocs.io/en/latest/data_types.html#module-sqlalchemy_utils.types.encrypted\u003e`_.\n\nContents\n********\n\n* `Implementation Details`_ \n* `Features`_\n* `Installation`_\n* `Usage`_\n* `Key Derivation Example`_\n\n.. _Implementation Details:\n\nImplementation Details\n----------------------\n\nA fernet-py_ package can use Pycrypto_ or `M2Crypto \u003chttps://pypi.python.org/pypi/M2Crypto\u003e`_ as backend (`details \u003chttps://github.com1/heroku/fernet-py#installation\u003e`_). Same belongs to this module due to its dependency from fernet-py_. Note that ``pip`` uses Pycrypto_ as a default dependency when install fernet-py_. \n**Length of entire key is 32 bytes**, 16 bytes per both signing and encryption keys, as stated in `specification \u003chttps://github.com/fernet/spec/blob/master/Spec.md#key-format\u003e`_.\n\n.. _Features:\n\nFeatures\n--------\n\nYou have to set ``key`` as a property of appropriate ``EncryptedField``. **You need to set this property once per** ``Model`` **per** ``Model`` **'s** ``Field``.\nIf you attempt to set ``key`` property for a ``Field`` whose ``key`` already has been set, exception ``EncryptedField.KeyAlreadyExists`` will be raised. To change the ``key`` on the fly you have to explictly perform ``del SomeEncryptedField.key`` and then set this property to desired value again.\n\n.. _Installation:\n\nInstallation\n------------\n\n``pip install peewee_encrypted_field``\n\nor, if you downloaded source, \n\n``python setup.py install``\n\n.. _Usage:\n\nUsage\n-----\n\nAt first, import module\n\n.. code-block:: python\n\n  from peewee import *\n  from peewee_encrypted_field import EncryptedField\n\nThen, define the model with :code:`EncryptedField`\n\n.. code-block:: python\n  \n  class SecureTable(BaseModel):\n      sensitive_data = EncryptedField()\n\n      class Meta:\n          db_table = 'SecureTable'\n\nAfter, configure field's encryption key\n\n.. code-block:: python\n  \n  SecureTable.sensitive_data.key = key_derivation_fn()  # a hypotetical key derivation \n                                                        # function returning 32 byte key\n\nFinally, save and retrieve data in a Peewee's usual manner\n\n.. code-block:: python\n\n  new_secret = SecureTable(sensitive_data='My New BIG Secret')\n  new_secret.save()\n\n.. _Key Derivation Example:\n\nKey Derivation Example\n----------------------\n\nExample Key Derivation Function baded on Pycrypto_ module.\n\n`Please take look at this Gist \u003chttps://gist.github.com/brake/18ab6f269fdef090034d1805308422c6\u003e`_ - it can contain more actual version of code below.\n\n.. code-block:: python\n\n  from binascii import unhexlify\n  from functools import partial\n  from Crypto.Protocol import KDF\n  from Crypto.Hash import SHA512, HMAC\n  \n  _SALT = unhexlify('48B755AB80CD1C3DA61182D3DCD2E3A2CA869B783618FF6551FB4B0CDC3B8066')  # some salt\n  _KEY_LENGTH = 32\n  \n  key_derivation_fn = partial(        \n      KDF.PBKDF2,\n      salt=_SALT,\n      dkLen=_KEY_LENGTH,\n      count=5000,\n      prf=lambda p,s: HMAC.new(p,s,SHA512).digest()\n  )\n\n  # KDF usage\n  SecureTable.sensitive_data.key = key_derivation_fn(text_password)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrake%2Fpeewee_encrypted_field","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrake%2Fpeewee_encrypted_field","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrake%2Fpeewee_encrypted_field/lists"}