pydantic_encryption 0.9.2__tar.gz → 0.9.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/PKG-INFO +6 -6
  2. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/README.md +5 -5
  3. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/integrations/sqlalchemy/descriptor.py +4 -6
  4. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pyproject.toml +1 -1
  5. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/LICENSE +0 -0
  6. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/__init__.py +0 -0
  7. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/adapters/__init__.py +0 -0
  8. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/adapters/base.py +0 -0
  9. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/adapters/blind_index/__init__.py +0 -0
  10. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/adapters/blind_index/argon2.py +0 -0
  11. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/adapters/blind_index/hmac_sha256.py +0 -0
  12. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/adapters/encryption/__init__.py +0 -0
  13. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/adapters/encryption/aws.py +0 -0
  14. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/adapters/encryption/fernet.py +0 -0
  15. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/adapters/hashing/__init__.py +0 -0
  16. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/adapters/hashing/argon2.py +0 -0
  17. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/adapters/registry.py +0 -0
  18. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/config.py +0 -0
  19. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/integrations/__init__.py +0 -0
  20. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/integrations/sqlalchemy/__init__.py +0 -0
  21. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/integrations/sqlalchemy/async_bridge.py +0 -0
  22. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/integrations/sqlalchemy/blind_index.py +0 -0
  23. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/integrations/sqlalchemy/bulk.py +0 -0
  24. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/integrations/sqlalchemy/deferred.py +0 -0
  25. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/integrations/sqlalchemy/encryption.py +0 -0
  26. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/integrations/sqlalchemy/hashing.py +0 -0
  27. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/integrations/sqlalchemy/serialization.py +0 -0
  28. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/integrations/sqlalchemy/state.py +0 -0
  29. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/lazy.py +0 -0
  30. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/models/__init__.py +0 -0
  31. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/models/base.py +0 -0
  32. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/normalization.py +0 -0
  33. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/pydantic_encryption/types.py +0 -0
  34. {pydantic_encryption-0.9.2 → pydantic_encryption-0.9.4}/scripts/run_tests.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pydantic_encryption
3
- Version: 0.9.2
3
+ Version: 0.9.4
4
4
  Summary: Encryption, hashing, and blind indexing for Pydantic
5
5
  License-File: LICENSE
6
6
  Author: Julien Kmec
@@ -51,7 +51,7 @@ Field-level encryption, hashing, and blind indexing for Pydantic models with SQL
51
51
  pip install pydantic-encryption
52
52
  ```
53
53
 
54
- ### Optional extras
54
+ ### Optional Extras
55
55
 
56
56
  ```bash
57
57
  pip install "pydantic-encryption[sqlalchemy]" # SQLAlchemy integration
@@ -220,11 +220,11 @@ async with AsyncSession(engine) as session:
220
220
  await decrypt_values(ciphertexts, concurrency=8) # flat ciphertexts; preserves None positions
221
221
  ```
222
222
 
223
- ### Safety: catching accidental ciphertext access
223
+ ### Safety: Catching Accidental Ciphertext Access
224
224
 
225
- Reads go through the on-access descriptor. If a `DeferredDecryptMixin` column is still encrypted when accessed on a **detached** instance (no session), the descriptor raises `EncryptedValueAccessError`; call `await instance.decrypt()` or `await decrypt_pending_fields(session)` first. Reads from plain async code (outside an SA greenlet) fall back to a synchronous batch decrypt across the session's pending siblings and return plaintext transparently.
225
+ Reads go through the on-access descriptor. When the underlying cell is still an `EncryptedValue`, the descriptor prefers an async batch decrypt over the session's pending siblings (via SQLAlchemy's greenlet bridge), and transparently falls back to a synchronous decrypt either when the read happens outside a greenlet or when the instance is detached from any session.
226
226
 
227
- If anything bypasses the descriptor and hands you an `EncryptedValue` directly (raw `state.dict[col]`, a logged row), coercing it via `str(value)` / `f"{value}"` / `"%s" % value` raises the same error. `repr(value)` is a safe `<EncryptedValue: N bytes>` marker, and `bytes(value)` returns the raw ciphertext. Use `is_encrypted(value)` to guard at a boundary.
227
+ An `EncryptedValue` only reaches user code if something bypasses the descriptor entirely (raw `state.dict[col]`, a logged row). Coercing it via `str(value)` / `f"{value}"` / `"%s" % value` raises `EncryptedValueAccessError`. `repr(value)` is a safe `<EncryptedValue: N bytes>` marker, and `bytes(value)` returns the raw ciphertext. Use `is_encrypted(value)` to guard at a boundary.
228
228
 
229
229
  ## Manual Encryption or Hashing
230
230
 
@@ -308,7 +308,7 @@ AWS_KMS_DECRYPT_KEY_ARN=arn:aws:kms:...decrypt-key
308
308
 
309
309
  Use one mode or the other — combining `AWS_KMS_KEY_ARN` with either split variant raises a validation error. A decrypt-only key alone is allowed (read-only workloads).
310
310
 
311
- #### Plaintext cache (opt-in)
311
+ #### Plaintext Cache (Opt-In)
312
312
 
313
313
  For read-heavy workloads that repeatedly decrypt the same ciphertexts, AWS KMS round-trips dominate. An in-process LRU of ciphertext → plaintext is available as opt-in:
314
314
 
@@ -8,7 +8,7 @@ Field-level encryption, hashing, and blind indexing for Pydantic models with SQL
8
8
  pip install pydantic-encryption
9
9
  ```
10
10
 
11
- ### Optional extras
11
+ ### Optional Extras
12
12
 
13
13
  ```bash
14
14
  pip install "pydantic-encryption[sqlalchemy]" # SQLAlchemy integration
@@ -177,11 +177,11 @@ async with AsyncSession(engine) as session:
177
177
  await decrypt_values(ciphertexts, concurrency=8) # flat ciphertexts; preserves None positions
178
178
  ```
179
179
 
180
- ### Safety: catching accidental ciphertext access
180
+ ### Safety: Catching Accidental Ciphertext Access
181
181
 
182
- Reads go through the on-access descriptor. If a `DeferredDecryptMixin` column is still encrypted when accessed on a **detached** instance (no session), the descriptor raises `EncryptedValueAccessError`; call `await instance.decrypt()` or `await decrypt_pending_fields(session)` first. Reads from plain async code (outside an SA greenlet) fall back to a synchronous batch decrypt across the session's pending siblings and return plaintext transparently.
182
+ Reads go through the on-access descriptor. When the underlying cell is still an `EncryptedValue`, the descriptor prefers an async batch decrypt over the session's pending siblings (via SQLAlchemy's greenlet bridge), and transparently falls back to a synchronous decrypt either when the read happens outside a greenlet or when the instance is detached from any session.
183
183
 
184
- If anything bypasses the descriptor and hands you an `EncryptedValue` directly (raw `state.dict[col]`, a logged row), coercing it via `str(value)` / `f"{value}"` / `"%s" % value` raises the same error. `repr(value)` is a safe `<EncryptedValue: N bytes>` marker, and `bytes(value)` returns the raw ciphertext. Use `is_encrypted(value)` to guard at a boundary.
184
+ An `EncryptedValue` only reaches user code if something bypasses the descriptor entirely (raw `state.dict[col]`, a logged row). Coercing it via `str(value)` / `f"{value}"` / `"%s" % value` raises `EncryptedValueAccessError`. `repr(value)` is a safe `<EncryptedValue: N bytes>` marker, and `bytes(value)` returns the raw ciphertext. Use `is_encrypted(value)` to guard at a boundary.
185
185
 
186
186
  ## Manual Encryption or Hashing
187
187
 
@@ -265,7 +265,7 @@ AWS_KMS_DECRYPT_KEY_ARN=arn:aws:kms:...decrypt-key
265
265
 
266
266
  Use one mode or the other — combining `AWS_KMS_KEY_ARN` with either split variant raises a validation error. A decrypt-only key alone is allowed (read-only workloads).
267
267
 
268
- #### Plaintext cache (opt-in)
268
+ #### Plaintext Cache (Opt-In)
269
269
 
270
270
  For read-heavy workloads that repeatedly decrypt the same ciphertexts, AWS KMS round-trips dominate. An in-process LRU of ciphertext → plaintext is available as opt-in:
271
271
 
@@ -14,7 +14,7 @@ from sqlalchemy.orm import object_session
14
14
 
15
15
  from pydantic_encryption.integrations.sqlalchemy.state import pending_siblings
16
16
  from pydantic_encryption.integrations.sqlalchemy.bulk import decrypt_rows, decrypt_rows_sync
17
- from pydantic_encryption.types import EncryptedValue, EncryptedValueAccessError
17
+ from pydantic_encryption.types import EncryptedValue
18
18
 
19
19
 
20
20
  class DecryptOnAccessDescriptor:
@@ -43,12 +43,10 @@ class DecryptOnAccessDescriptor:
43
43
 
44
44
  session = object_session(instance)
45
45
  if session is None:
46
- raise EncryptedValueAccessError(
47
- f"Cannot decrypt {self._cls.__name__}.{self._column_key} on a detached instance. "
48
- "Call `await instance.decrypt()` or `await decrypt_pending_fields(session)` first."
49
- )
46
+ rows: list[Any] | set[Any] = [instance]
47
+ else:
48
+ rows = {instance, *pending_siblings(session, self._cls)}
50
49
 
51
- rows = {instance, *pending_siblings(session, self._cls)}
52
50
  try:
53
51
  await_(decrypt_rows(rows, self._column_key))
54
52
  except MissingGreenlet:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pydantic_encryption"
3
- version = "0.9.2"
3
+ version = "0.9.4"
4
4
  description = "Encryption, hashing, and blind indexing for Pydantic"
5
5
  authors = [
6
6
  { name = "Julien Kmec", email = "me@julien.dev" },