profile_store
sqllocks_spindle.inference.profile_store
¶
ProfileStore — the single supported on-disk path for SafeProfile (STORY-003).
This module is the canonical, only-supported public on-disk entrypoint for
persisting and retrieving a :class:~sqllocks_spindle.inference.safe_profile.SafeProfile
(ADR-001 / ADR-007). The rich in-memory DatasetProfile (profiler.py) is
the source; SafeProfile is the transport; ProfileStore is the door
to disk.
Public API¶
- :meth:
ProfileStore.save— write aSafeProfileto a JSON file via itsto_safe_dictrepresentation. Returns the resolved path. - :meth:
ProfileStore.load— read a JSON file written bysaveand return a reconstructedSafeProfile. A file whoseschema_versionis unknown to the current code (legacy0or any future version) is loaded read-only with a warning — never a crash (ADR-001: legacy files load read-only asschema_version=0).
There is no other public on-disk path. Legacy serialization paths
(ProfileRegistry, ProfileIO) are re-pointed at ProfileStore in
STORY-014; until then they remain but are not the supported safe path.
Scope note (STORY-003): this story owns the save/load round-trip + legacy
schema_version handling.
Safe-by-default (STORY-009 / ADR-005): the scrub (winsorize + k-anon + PII
gate) runs at MAPPING time (SafeProfile.from_dataset_profile), so a
SafeProfile reaching save is already safe-by-construction. save
writes the profile's unsafe stamp and embedded redaction_manifest as-is
— a SafeProfile built with unsafe_full_fidelity=True is persisted with
"unsafe": true in the artifact (and rejected later by validate --safe,
STORY-010). SafeProfile carries no raw-bearing fields by construction
(STORY-001 / ADR-007), so there is nothing here to refuse.
Classes¶
ProfileStore
¶
Persist and retrieve a :class:SafeProfile to/from a JSON file.
All methods are stateless — instantiate with ProfileStore() and call
directly, or use the classmethods. This is the only supported public
on-disk entrypoint for a SafeProfile (ADR-001 / ADR-007).
Methods:¶
save(profile, path)
classmethod
¶
Write profile to path as JSON (via to_safe_dict).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile
|
SafeProfile
|
The :class: |
required |
path
|
str | Path
|
Destination file path. Parent directories are created. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The resolved :class: |
load(path)
classmethod
¶
Read a SafeProfile from a JSON file written by :meth:save.
A file whose schema_version is not the version this code writes
(e.g. a legacy artifact with no/old version, or a future version) is
loaded read-only with a warning — it never crashes. The returned
object is degraded-but-usable: the keys present are reconstructed, and
the loaded schema_version is preserved on the returned object so a
caller can detect the mismatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to a JSON file previously written by :meth: |
required |
Returns:
| Type | Description |
|---|---|
SafeProfile
|
A reconstructed :class: |