Fast Fernet bindings for Python
Project description
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)
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
rfernet-0.3.1.tar.gz
(6.8 kB
view hashes)
Built Distributions
Close
Hashes for rfernet-0.3.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 350ae766a0d6acc3ef4f13de7cf4bbd392980ce5eec7ba89a6724f2f591355eb |
|
MD5 | 011ba969604049616807f0b231cb3978 |
|
BLAKE2b-256 | 540e110059601da363702e4f3ee99942048dccf0267c1ed51b3f1e8d4cb40159 |
Close
Hashes for rfernet-0.3.1-cp311-cp311-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b30a03cacf89b74ae55beabb4856f431ef4e2dd665f3c520924cf2900b531893 |
|
MD5 | 9b0ccb04242f8194628d193912f920ca |
|
BLAKE2b-256 | 701242a7dd097b4ae23c69e54f4eaf0a9294d05afbd5953fd2707ccaa01d92f3 |
Close
Hashes for rfernet-0.3.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6abb5d3bbf550759c734048c628f4ba80e13e468221db4f037d880edf123ba8a |
|
MD5 | 50c757fae892d335c4d76bda6bb2412a |
|
BLAKE2b-256 | 11b20fa6ea2f6d4e6f18bd394cae47e32a82938e88071ab8c81abf50161dc1b7 |
Close
Hashes for rfernet-0.3.1-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3771a59dc8c84f531fa37ff1a8dbe23db8cc67e5f5244ebcf5482335b4df567 |
|
MD5 | 62633749f23dd3204ec5b5ccea594211 |
|
BLAKE2b-256 | 67dde85a155008466e0509907ef2293862fdd1cc8fbf784778a777e388ddae97 |
Close
Hashes for rfernet-0.3.1-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09560657f0600df774d4346f7cd3ed409840b0b02b5ee9ec744bc12d67880cc4 |
|
MD5 | 1de3b31811ff19083f8771b936b0b7f4 |
|
BLAKE2b-256 | 1aa3a77acea59bc6d6cafd81409e6bf71093509c1f00424921cfe1476e07faee |
Close
Hashes for rfernet-0.3.1-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d24e2f107edb68e12dd2e2298a69944f177767d67abb4407ed20e41a3a1a102 |
|
MD5 | c73daf92ee2a5a09c9b89a01d0b1fb1e |
|
BLAKE2b-256 | 48e8e7b3ef5180c86796ea10b8ec63cb3ea5ee759786e776710c4303266fbdb8 |
Close
Hashes for rfernet-0.3.1-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98018a785785b4a2cc383bd9c4597057f620e57e6a6bd1c3517d5813e7e33969 |
|
MD5 | 6af4f82bbf98649680b640e0dc4887c3 |
|
BLAKE2b-256 | d96902781ebc80e9843fed1fc2566fba378778f33f33c3a5d2f9f383aa1d95bd |
Close
Hashes for rfernet-0.3.1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b8ee5a9a61fad41764141809a9a1f8da1844134de85f8216110ba69f4c87610 |
|
MD5 | 8d4521a3e5e3c8928407b7f760453519 |
|
BLAKE2b-256 | 6f781e9d7edf1ab546b3e422c8310875b02ae1e696ac903835149b97b681c0f2 |
Close
Hashes for rfernet-0.3.1-cp37-cp37m-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9607702f8c7ebeab32bdf5661f2cff7ae4b6341f31ea48bb8582078a300b5415 |
|
MD5 | be8cf079ebe5b823921a1efbec22a4a3 |
|
BLAKE2b-256 | ccaac646b19278c8a6a517bee38aacb4f31ec70e7b19d6561c8bbced18b925f2 |
Close
Hashes for rfernet-0.3.1-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | faf9973e365253a273b8342fa26f15b56b971c4be29712ea2a3c7076b34ad720 |
|
MD5 | 5ed6a5cd4fcdf0203c0ba0155051a49d |
|
BLAKE2b-256 | 5ebde126b704d6c16a5216155dd26d21388e197ee71d91938987baeb05e1f98c |