truhe
Encrypted blob stores. An application puts its bytes into a store and gets them back; the store, S3, a directory or memory, only ever sees ciphertext.
AES-256-GCM in 64 KiB blocks, so objects of any size stream in and out without being held in memory.
Stores for S3 compatible object storage, the filesystem and memory.
Synchronous over urllib3, asynchronous over httpx.
AWS Signature Version 4 of its own, no SDK.
Keys rotate without rewriting the store.
Installation
The S3 store needs an HTTP client, chosen with an extra:
pip install truhe[urllib3] # synchronous
pip install truhe[httpx] # asynchronous
Without extra, the filesystem and the memory store are available.
Usage
A store wrapped in EncryptedBlobStore encrypts on the way in and decrypts on the way out:
import os
from truhe import EncryptedBlobStore
from truhe import Keyring
from truhe.s3 import S3BlobStore
from truhe.sigv4 import Credentials
credentials = Credentials(
access_key='...',
secret_key='...',
region='fsn1',
)
store = EncryptedBlobStore(
S3BlobStore(credentials, 'https://fsn1.your-objectstorage.com', 'bucket'),
Keyring.from_setting(keys),
magic=b'MYAPP',
)
# bytes
store.put('reports/2026/q3.pdf', data, 'application/pdf')
# a stream, with its length up front
with open('intro.mp4', 'rb') as f:
store.put(
'videos/intro.mp4',
iter(lambda: f.read(65536), b''),
'video/mp4',
content_length=os.fstat(f.fileno()).st_size,
)
with store.open('videos/intro.mp4') as stream:
for chunk in stream.chunks:
...
store.head('videos/intro.mp4') # StoredBlob(size=..., content_type=...)
list(store.list('videos/')) # ListedBlob(key, size, modified)
store.delete('videos/intro.mp4')
The asynchronous stores have the same operations as coroutines, open is an async context manager, list an async iterator, a stream to put an async iterable:
import httpx
from truhe.aio import EncryptedBlobStore
from truhe.aio.s3 import S3BlobStore
async with httpx.AsyncClient() as client:
store = EncryptedBlobStore(
S3BlobStore(credentials, endpoint, 'bucket', client),
keyring,
)
await store.put('k', data, 'application/octet-stream')
async with store.open('k') as stream:
async for chunk in stream.chunks:
...
Sizes are always plaintext sizes, the framing stays inside EncryptedBlobStore.
Streams
put takes bytes, or an iterable of bytes together with content_length. A stream which delivers more or fewer bytes than announced fails, and nothing is stored: the piece which would complete the object is only passed on once the stream is known to end there.
Bytes go to S3 with their SHA-256 in the signature and Content-MD5, so the store verifies what arrived. A stream goes out with UNSIGNED-PAYLOAD and its Content-Length; hashing it first would mean holding it. One request per object, so an object is at most 5 GiB, the limit of a single PUT.
Keys
A Keyring holds 32 byte keys, newest first. New objects are sealed with the first, every object names its key in its header. To rotate, put a new key in front, old objects stay readable. Dropping a key makes its objects unreadable.
openssl rand -hex 32
Keyring.from_setting reads a comma separated list of hex keys, the form of an environment variable. Keyring.primary_id is the id of the current key, worth recording next to every object, so the progress of a rotation is a query.
The key is the data. Lose it, and every object is gone while the store is perfectly healthy.
S3 compatible stores
S3BlobStore addresses the bucket virtual hosted, {bucket}.{endpoint host}, the form most providers document. Pass path_style=True for {endpoint}/{bucket}, e.g. MinIO or Garage without a domain. The region is the location code of the provider.
The stores do not retry. A retried upload after a lost answer is the application’s decision.
Format
An object is a header and its sealed blocks:
Field |
Bytes |
Content |
|---|---|---|
magic |
5 |
names the application, TRUHE by default |
version |
1 |
1 |
key id |
8 |
truncated SHA-256 of the key |
nonce prefix |
8 |
random per object |
blocks |
n |
64 KiB plaintext each, the last one shorter, sealed with AES-256-GCM, 16 byte tag |
The nonce of a block is the prefix and the block counter, the associated data is the header and a flag for the last block. So a block cannot be reordered or moved to another object, a truncated object does not verify, and a header cannot be swapped. An empty object has one sealed empty block.
truhe.format has the format without I/O: Sealer and Opener take bytes as they arrive and return complete blocks, ciphertext_length gives the stored size before the first byte.
Not supported: HTTP Range, multipart uploads, presigned URLs.
Tests
make install
make test
The S3 stores are tested offline. The tests against a store are opt-in, make test skips them. To run them against a throwaway MinIO:
make test-s3
This starts the container from testing/compose.minio.yml, runs the S3 tests and discards the container, also when a test fails. To keep it running while working on the tests:
./scripts/minio.sh up
eval "$(./scripts/minio.sh env)"
make test
./scripts/minio.sh down
The store is selected by TRUHE_TEST_S3_ENDPOINT, TRUHE_TEST_S3_ACCESS_KEY, TRUHE_TEST_S3_SECRET_KEY, TRUHE_TEST_S3_REGION and TRUHE_TEST_S3_BUCKET, plus TRUHE_TEST_S3_PATH_STYLE=1 if needed. The bucket is emptied before each test, so it must be one which holds nothing else.
Contributors
Robert Niederreiter
Changes
1.0.0 (2026-11-04)
Initial release. Encrypted blob store with stores for memory, the filesystem and S3, synchronous over urllib3, asynchronous over httpx. AES-256-GCM in 64 KiB blocks, streaming in both directions. [rnix]
License
MIT License
Copyright (c) 2026 Conestack
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Metadata
Release files for truhe 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| truhe-1.0.0.tar.gz | 34.1 kB | Without provenance | Details for truhe-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| truhe-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for truhe-1.0.0-py3-none-any.whl |
Total release size: 77.4 kB
Release files / truhe-1.0.0.tar.gz
| Download URL | truhe-1.0.0.tar.gz |
|---|---|
| Size | 34.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35104430fa73a1258466315c85e440b8729a08376b0a42b923e7984096988dfa
|
|
BLAKE2b-256 checksum How to use checksums |
be9fc51f4d31875c06f25a2bbb2499afc8c8bf1a1ec8c3c55f43cd5270e09759
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.2
|
Release files / truhe-1.0.0-py3-none-any.whl
| Download URL | truhe-1.0.0-py3-none-any.whl |
|---|---|
| Size | 43.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e0e23d7045f03028c79ce140eb9c8736393117ac233961973c3493ef9e9343ab
|
|
BLAKE2b-256 checksum How to use checksums |
7303985b186c30869ceebfa539b770e6d1949696c79705285a0cfae469607359
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.2
|
Security for truhe 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.