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.2.0.tar.gz
(3.6 kB
view hashes)
Built Distributions
Close
Hashes for rfernet-0.2.0-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60db4cf220afc4c6dbfe9e5685373e21f13bced2c9849b7efdfb41b581fed476 |
|
MD5 | e8bd30f2e8f3edbb36377509ba0f38a2 |
|
BLAKE2b-256 | e6b34067b7416b40ca1923025ac31817c5e8ba6d2ddb6e37609f8bcc9d462a18 |
Close
Hashes for rfernet-0.2.0-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa1156a6edff8758fc56a9cdf20b43dc4a484f5d890e08bc2673fa8d48099f36 |
|
MD5 | 86556d52b9b6eb3ba8c8ca9a470ec5ba |
|
BLAKE2b-256 | 70b5f5051ec98fe5f00579966184a665e372b528c9714925557c02ec40759c93 |
Close
Hashes for rfernet-0.2.0-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f0f2e01d0cdc7da113e4df4212ea03f6de8c607fcc4368e91774adc57aba135 |
|
MD5 | f138c919e09469800714a3076a152072 |
|
BLAKE2b-256 | 906464fb6249b08b3959ac0cfe728f26e236bad7b7a0afd2e01044a525a5e6a5 |
Close
Hashes for rfernet-0.2.0-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0fa82d19882d08f67cf081b79ba3ffd485da8d97586875ee13c175ba0ab2ddc |
|
MD5 | 03491272b8b7fc5aa109ade50704111f |
|
BLAKE2b-256 | 54ec54535d87dcc3328bf8b42608b3dda111608ccd39d222ffe28e1128ac4d1e |
Close
Hashes for rfernet-0.2.0-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8117b80227b512adbcf1eba1ccca6753db9b07b834b8ab083be1bd7c6958ce1c |
|
MD5 | fad564dd921a8189da1207b7bf83e14a |
|
BLAKE2b-256 | 3f966569eea10bac55b304ad5e2566998dfdb9d72d73325ae79d9e6362bcf472 |
Close
Hashes for rfernet-0.2.0-cp37-cp37m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1a82111976c4ec0fb720aa6afeb98ffe267a91ef97b2fd46d7f144702a57e15 |
|
MD5 | a63fb7d4a416ae001e43c9ee6f03128a |
|
BLAKE2b-256 | 5e682c7b127f4e3813d03c5daaf67100b8810b782468ed56013dfc15d9fd18de |
Close
Hashes for rfernet-0.2.0-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58306118e48b2752f81e961e8f0ff652ea466d5cf97ae73d282978f2a46ab4d7 |
|
MD5 | 509ba017de31e8a5e886a7e1402ef3dd |
|
BLAKE2b-256 | 71cae8a8b2cd226ec36e6642ca265ee9111f4721485cdd7adbe24827e1e94ee7 |
Close
Hashes for rfernet-0.2.0-cp36-cp36m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df42caed5b5462c7d781182c37e05d34c03b4c88293a0a875b2f6d8be7ff11e0 |
|
MD5 | 9283fc86af4ccf44e506a1b968c82db7 |
|
BLAKE2b-256 | 7db6027579906fd044f77b42a1aaf213edb37a899705bcd53db905dacb23ba6b |
Close
Hashes for rfernet-0.2.0-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c195b94453e1b2dc5e4ed1f1977c819b49fbc3bcb811e2bbd3f160c48538eee9 |
|
MD5 | 38769b6981513b5f9b832a8b20b93667 |
|
BLAKE2b-256 | 8f57557b350476828f8e9f3d294da449eda1a52783dbafb88ef9c070ed6734f0 |