# rfernet
Python extension for Fernet encryption/decryption, faster than other alternatives.
This library uses the rust library `fernet-rs` https://github.com/mozilla-services/fernet-rs.
CI & Building wheels copied from `cryptography` and `orjson`
# Benchmark
Compared to cryptography's Fernet (CPU):
```
In [2]: from cryptography.fernet import Fernet as cFernet
In [3]: from rfernet import Fernet as rFernet
In [4]:
In [4]: plain = b"asd" * 1000
In [5]: key = rFernet.generate_new_key()
In [7]: r_fernet = rFernet(key)
In [8]: c_fernet = cFernet(key)
In [9]: %timeit r_fernet.encrypt(plain)
18.4 µs ± 117 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
In [10]: %timeit c_fernet.encrypt(plain)
77.7 µs ± 921 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
```
Memory:
```
# rfernet
[ Top 10 ]
<frozen importlib._bootstrap>:219: size=4444 B, count=38, average=117 B
test2.py:4: size=576 B, count=1, average=576 B
<frozen importlib._bootstrap_external>:59: size=156 B, count=1, average=156 B
test2.py:6: size=93 B, count=1, average=93 B
<frozen importlib._bootstrap>:371: size=80 B, count=1, average=80 B
<frozen importlib._bootstrap>:105: size=72 B, count=1, average=72 B
<frozen importlib._bootstrap_external>:1352: size=56 B, count=1, average=56 B
<frozen importlib._bootstrap_external>:606: size=56 B, count=1, average=56 B
test2.py:7: size=48 B, count=1, average=48 B
<frozen importlib._bootstrap_external>:1030: size=40 B, count=1, average=40 B
# cryptography's Fernet
[ Top 10 ]
<frozen importlib._bootstrap_external>:525: size=3134 KiB, count=31814, average=101 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py:91: size=449 KiB, count=3169, average=145 B
<frozen importlib._bootstrap>:219: size=404 KiB, count=3384, average=122 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/abc.py:126: size=146 KiB, count=717, average=209 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py:89: size=119 KiB, count=1773, average=69 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/abc.py:127: size=68.7 KiB, count=447, average=157 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py:2793: size=46.8 KiB, count=282, average=170 B
<frozen importlib._bootstrap_external>:59: size=41.7 KiB, count=265, average=161 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/abc.py:135: size=40.8 KiB, count=339, average=123 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/idna/idnadata.py:826: size=36.7 KiB, count=3, average=12.2 KiB
```
Memory test source code:
```
import tracemalloc
tracemalloc.start()
from cryptography.fernet import Fernet as cFernet
plain = b"asd" * 1000
key = cFernet.generate_key()
c_fernet = cFernet(key)
c_fernet.encrypt(plain)
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')
print("[ Top 10 ]")
for stat in top_stats[:10]:
print(stat)
```
Raw data
{
"_id": null,
"home_page": null,
"name": "rfernet",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "fast, fernet",
"author": "Aviram Hassan <aviramyhassan@gmail.com>",
"author_email": "Aviram Hassan <aviramyhassan@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/72/bc/80feb51080f869246e0575d56fbc0faa409051f5a73b3731589c45d99d63/rfernet-0.3.3.tar.gz",
"platform": null,
"description": "# rfernet\nPython extension for Fernet encryption/decryption, faster than other alternatives.\nThis library uses the rust library `fernet-rs` https://github.com/mozilla-services/fernet-rs.\n\nCI & Building wheels copied from `cryptography` and `orjson`\n\n# Benchmark\nCompared to cryptography's Fernet (CPU):\n```\nIn [2]: from cryptography.fernet import Fernet as cFernet\n\nIn [3]: from rfernet import Fernet as rFernet\n\nIn [4]:\n\nIn [4]: plain = b\"asd\" * 1000\n\nIn [5]: key = rFernet.generate_new_key()\n\nIn [7]: r_fernet = rFernet(key)\n\nIn [8]: c_fernet = cFernet(key)\n\nIn [9]: %timeit r_fernet.encrypt(plain)\n18.4 \u00b5s \u00b1 117 ns per loop (mean \u00b1 std. dev. of 7 runs, 100000 loops each)\n\nIn [10]: %timeit c_fernet.encrypt(plain)\n77.7 \u00b5s \u00b1 921 ns per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n```\nMemory:\n```\n# rfernet\n[ Top 10 ]\n<frozen importlib._bootstrap>:219: size=4444 B, count=38, average=117 B\ntest2.py:4: size=576 B, count=1, average=576 B\n<frozen importlib._bootstrap_external>:59: size=156 B, count=1, average=156 B\ntest2.py:6: size=93 B, count=1, average=93 B\n<frozen importlib._bootstrap>:371: size=80 B, count=1, average=80 B\n<frozen importlib._bootstrap>:105: size=72 B, count=1, average=72 B\n<frozen importlib._bootstrap_external>:1352: size=56 B, count=1, average=56 B\n<frozen importlib._bootstrap_external>:606: size=56 B, count=1, average=56 B\ntest2.py:7: size=48 B, count=1, average=48 B\n<frozen importlib._bootstrap_external>:1030: size=40 B, count=1, average=40 B\n\n# cryptography's Fernet\n[ Top 10 ]\n<frozen importlib._bootstrap_external>:525: size=3134 KiB, count=31814, average=101 B\n/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py:91: size=449 KiB, count=3169, average=145 B\n<frozen importlib._bootstrap>:219: size=404 KiB, count=3384, average=122 B\n/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/abc.py:126: size=146 KiB, count=717, average=209 B\n/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py:89: size=119 KiB, count=1773, average=69 B\n/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/abc.py:127: size=68.7 KiB, count=447, average=157 B\n/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py:2793: size=46.8 KiB, count=282, average=170 B\n<frozen importlib._bootstrap_external>:59: size=41.7 KiB, count=265, average=161 B\n/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/abc.py:135: size=40.8 KiB, count=339, average=123 B\n/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/idna/idnadata.py:826: size=36.7 KiB, count=3, average=12.2 KiB\n```\nMemory test source code:\n```\nimport tracemalloc\n\ntracemalloc.start()\nfrom cryptography.fernet import Fernet as cFernet\nplain = b\"asd\" * 1000\nkey = cFernet.generate_key()\nc_fernet = cFernet(key)\nc_fernet.encrypt(plain)\n\nsnapshot = tracemalloc.take_snapshot()\ntop_stats = snapshot.statistics('lineno')\n\nprint(\"[ Top 10 ]\")\nfor stat in top_stats[:10]:\n print(stat)\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Fast Fernet bindings for Python",
"version": "0.3.3",
"project_urls": null,
"split_keywords": [
"fast",
" fernet"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9c095dd7512128348d8987c860d01b1cacf9b8f3d3a40f82b69c63c82b6db98c",
"md5": "1e01dedf57e88154c9673ada658fa971",
"sha256": "ea0300e0e4aaeedc912804a7a39f00ba29642054ab7e5c778e7d023423ff8407"
},
"downloads": -1,
"filename": "rfernet-0.3.3-cp310-cp310-manylinux_2_28_x86_64.whl",
"has_sig": false,
"md5_digest": "1e01dedf57e88154c9673ada658fa971",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": ">=3.8",
"size": 1960793,
"upload_time": "2024-10-15T13:46:59",
"upload_time_iso_8601": "2024-10-15T13:46:59.531481Z",
"url": "https://files.pythonhosted.org/packages/9c/09/5dd7512128348d8987c860d01b1cacf9b8f3d3a40f82b69c63c82b6db98c/rfernet-0.3.3-cp310-cp310-manylinux_2_28_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "428682d4aa5e83b4102e7873e8a27992df7e9f4b17aa36bec0df2f6521cb437c",
"md5": "359be1dc849d02328358ebbc44d82dce",
"sha256": "8e2e0dad54d37c0c259b3e1916fea17e567d81b1861b1f301fd0aafdbae63fdf"
},
"downloads": -1,
"filename": "rfernet-0.3.3-cp311-cp311-manylinux_2_28_x86_64.whl",
"has_sig": false,
"md5_digest": "359be1dc849d02328358ebbc44d82dce",
"packagetype": "bdist_wheel",
"python_version": "cp311",
"requires_python": ">=3.8",
"size": 1960867,
"upload_time": "2024-10-15T13:46:53",
"upload_time_iso_8601": "2024-10-15T13:46:53.796226Z",
"url": "https://files.pythonhosted.org/packages/42/86/82d4aa5e83b4102e7873e8a27992df7e9f4b17aa36bec0df2f6521cb437c/rfernet-0.3.3-cp311-cp311-manylinux_2_28_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3357f414391d818391a1617de2fbb879e33df944584313585cc8685ee6a9e8f9",
"md5": "5b473bf0f82e70eef2650422689b24e2",
"sha256": "2e379b91f2ae8e46b5cf0ff8d44a430598a0c58bde261742051df68b2376da41"
},
"downloads": -1,
"filename": "rfernet-0.3.3-cp312-cp312-manylinux_2_28_x86_64.whl",
"has_sig": false,
"md5_digest": "5b473bf0f82e70eef2650422689b24e2",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": ">=3.8",
"size": 1960909,
"upload_time": "2024-10-15T13:46:57",
"upload_time_iso_8601": "2024-10-15T13:46:57.507471Z",
"url": "https://files.pythonhosted.org/packages/33/57/f414391d818391a1617de2fbb879e33df944584313585cc8685ee6a9e8f9/rfernet-0.3.3-cp312-cp312-manylinux_2_28_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "68ed76f98a3e48f7cee6f66cbcb432c91d60d9aef98ccd671b1c5d767cf4a60f",
"md5": "be656124c97b99f78439e5ba5249f4e3",
"sha256": "e48e8e9ab504e815064ee353c0de755db8ea535455e75b418faa0462dd0a145b"
},
"downloads": -1,
"filename": "rfernet-0.3.3-cp38-cp38-manylinux_2_28_x86_64.whl",
"has_sig": false,
"md5_digest": "be656124c97b99f78439e5ba5249f4e3",
"packagetype": "bdist_wheel",
"python_version": "cp38",
"requires_python": ">=3.8",
"size": 1961065,
"upload_time": "2024-10-15T13:47:32",
"upload_time_iso_8601": "2024-10-15T13:47:32.400309Z",
"url": "https://files.pythonhosted.org/packages/68/ed/76f98a3e48f7cee6f66cbcb432c91d60d9aef98ccd671b1c5d767cf4a60f/rfernet-0.3.3-cp38-cp38-manylinux_2_28_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e3e2858e0cd91b29f46bf7b9a6548758277e2eeb521938345a6a4a69b992a944",
"md5": "5afd5b21495f63e26a7a464f29fadba1",
"sha256": "723decc574fd44ee8c67d63a0b711510ecaf585c912bb6c8e3859ea1d2a495f7"
},
"downloads": -1,
"filename": "rfernet-0.3.3-cp39-cp39-manylinux_2_28_x86_64.whl",
"has_sig": false,
"md5_digest": "5afd5b21495f63e26a7a464f29fadba1",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.8",
"size": 1961484,
"upload_time": "2024-10-15T13:47:03",
"upload_time_iso_8601": "2024-10-15T13:47:03.113505Z",
"url": "https://files.pythonhosted.org/packages/e3/e2/858e0cd91b29f46bf7b9a6548758277e2eeb521938345a6a4a69b992a944/rfernet-0.3.3-cp39-cp39-manylinux_2_28_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "72bc80feb51080f869246e0575d56fbc0faa409051f5a73b3731589c45d99d63",
"md5": "8e228635d8e3ab622fe2afde79f2f9d2",
"sha256": "090e2cf80776828d7c67f1d71e87c82ff27b7e1cfb40ef3c594a0267d5e64fff"
},
"downloads": -1,
"filename": "rfernet-0.3.3.tar.gz",
"has_sig": false,
"md5_digest": "8e228635d8e3ab622fe2afde79f2f9d2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 6832,
"upload_time": "2024-10-15T13:45:50",
"upload_time_iso_8601": "2024-10-15T13:45:50.941005Z",
"url": "https://files.pythonhosted.org/packages/72/bc/80feb51080f869246e0575d56fbc0faa409051f5a73b3731589c45d99d63/rfernet-0.3.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-15 13:45:50",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "rfernet"
}