Still Charger API
Overview
gkc.still_charger is the packet assembly and source charging module.
It owns:
- Building curation packet scaffolds from JSON Entity Profiles.
- Charging packet entities from source systems (currently Wikidata via
mash). - Producing packet-level conformance payloads by orchestrating fermenter primitives.
- Maintaining packet metadata integrity sealing after charge-time metadata mutation.
It does not own validation semantics. Fermenter owns validation outcomes and notice semantics.
Contract Shape
Curation packets follow a strict three-section top-level shape:
metadatadataconformance
Source metadata for charged packets is recorded in metadata.profiles[*] and includes:
source_qidlastrevidpulled_at
After source metadata injection, still_charger reseals metadata.integrity.metadata_digest.
Quick Start
from gkc.still_charger import create_curation_packet, charge_packet_from_wikidata_items
from gkc.spirit_safe import set_spirit_safe_source
set_spirit_safe_source(mode="local", local_root="/path/to/SpiritSafe")
packet = create_curation_packet("Q4", operation_mode="single")
qid_map = {entity["id"]: "Q195562" for entity in packet["data"]["entities"]}
charged_packet, notices = charge_packet_from_wikidata_items(packet, qid_map)
print(charged_packet["metadata"]["profiles"][0].get("source_qid"))
print(charged_packet["metadata"]["integrity"]["metadata_digest_algorithm"])
print(len(notices))
Public API
create_curation_packet
Create a packet scaffold from SpiritSafe profile JSON.
from gkc.still_charger import create_curation_packet
packet = create_curation_packet("Q4", operation_mode="single")
Arguments:
| Argument | Type | Meaning |
|---|---|---|
profile_id |
str |
Profile QID or full profile URI |
operation_mode |
str |
single for primary profile only, bulk for profile-graph expansion |
Returns:
- Packet scaffold with
metadata,data, and emptyconformancetarget surface.
build_curation_packet_from_json_profile
Assemble a packet scaffold from a loaded JSON profile document.
from pathlib import Path
from gkc.still_charger import build_curation_packet_from_json_profile
packet = build_curation_packet_from_json_profile(
profile_entity="https://datadistillery.wikibase.cloud/entity/Q4",
json_profile_doc=json_profile_doc,
source_root=Path("/path/to/SpiritSafe"),
)
Arguments:
| Argument | Type | Meaning |
|---|---|---|
profile_entity |
str |
Profile URI or QID |
json_profile_doc |
dict |
Parsed JSON profile document |
source_root |
Path | None |
Optional SpiritSafe local root for value-list route resolution |
source_config |
dict | None |
Optional source descriptor stored under metadata.source |
Returns:
- Uncharged packet scaffold with sealed metadata integrity digest.
charge_packet_from_wikidata_items
Charge a packet from Wikidata entities and emit conformance payloads.
from gkc.still_charger import charge_packet_from_wikidata_items
charged_packet, notices = charge_packet_from_wikidata_items(packet, qid_map)
Arguments:
| Argument | Type | Meaning |
|---|---|---|
packet |
dict |
Packet assembled by build_curation_packet_from_json_profile |
qid_map |
dict[str, str] |
Maps profile URI or profile name_identifier to Wikidata QID |
mash_client |
Any | None |
Optional WikibaseLoader-compatible client |
Returns:
| Position | Type | Meaning |
|---|---|---|
0 |
dict |
Charged packet |
1 |
list[ConformanceNotice] |
Packet notices (currently empty placeholder list for this path) |
Charge behavior:
- Resolves linked entities via profile linkage routes.
- Loads primary and linked entity JSON from Wikidata.
- Populates packet data entities with source payloads.
- Injects source provenance fields into
metadata.profiles[*]. - Builds
conformancepayload from fermenter statement evaluators. - Reseals metadata digest after metadata mutation.
Current runtime note:
data.entitiesremains a transitional hybrid surface in current implementation (scaffold slots plus embedded raw entity payload).- Contract direction in #200 is to eliminate hybrid slot decoration from packet
dataand keep evaluation semantics inconformanceonly.
charge_curation_packet (Legacy)
Legacy direct-charge path from caller-provided source values.
from gkc.still_charger import charge_curation_packet
charged_packet, report = charge_curation_packet(packet, source_values)
New workflows should prefer charge_packet_from_wikidata_items.
ChargeIssue and ChargeReport
ChargeIssue captures a non-fatal charging issue.
ChargeReport summarizes charge results:
entities_chargedentities_skippedissues
Metadata Integrity and Provenance
Metadata digest behavior:
- Packet scaffolds are sealed at build time.
- Charged packets inject source provenance into
metadata.profiles[*]. - Metadata is resealed after provenance injection.
This supports packet re-presentation checks where metadata integrity and source revision context must be evaluated together.
Conformance Output Interface
still_charger orchestrates conformance payload construction and delegates atomic statement evaluation to fermenter:
evaluate_statement_instancestatement_evaluation_to_record
Ownership split:
still_charger: packet orchestration, source loading, packet mutation order.fermenter: statement-level evaluation semantics and record serialization.
API Reference (mkdocstrings)
ChargeIssue
Represents a non-fatal charging issue.
Source code in gkc/still_charger.py
28 29 30 31 32 33 34 35 | |
ChargeReport
Summary of a charge operation.
Source code in gkc/still_charger.py
38 39 40 41 42 43 44 | |
create_curation_packet
Create a curation packet scaffold from SpiritSafe JSON profiles.
This is the canonical packet-assembly entrypoint. It loads the primary
profile from SpiritSafe, applies operation-mode expansion policy, and
delegates scaffold construction to build_curation_packet_from_json_profile.
Source code in gkc/still_charger.py
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | |
build_curation_packet_from_json_profile
Build a curation packet from a JSON Entity Profile document.
This is the first stage of the still_charger pipeline: assembling a blank curation packet scaffold from a pre-loaded JSON profile, ready to be charged with concrete values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile_entity
|
str
|
Full entity URI (e.g., "https://datadistillery.wikibase.cloud/entity/Q4") or QID (e.g., "Q4") |
required |
json_profile_doc
|
dict
|
The loaded JSON Entity Profile document |
required |
source_root
|
Optional[Path]
|
Optional path root for resolving value list cache files; if provided, item_count will be hydrated from cache JSON |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary representing the curation packet matching the frozen contract: |
dict
|
{
"packet_id": "pkt- |
dict
|
} |
Source code in gkc/still_charger.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 | |
charge_packet_from_wikidata_items
Charge a curation packet with raw Wikibase entity JSON and conformance evaluation.
This is the primary charging entry point. It first resolves the linked entity graph from primary entity claims, then loads linked entities and populates the data section with raw Wikibase JSON.
Raw entity JSON is stored unmodified in data.entities[].entity. Conformance evaluation (statement-level alignment vs. profile) is stored separately in conformance.statement_evaluations using JSON paths. Labels, descriptions, and aliases are passed through without conformance evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
packet
|
dict[str, Any]
|
Curation packet assembled by build_curation_packet_from_json_profile() |
required |
qid_map
|
dict[str, str]
|
Mapping from profile entity URI or profile name_identifier to Wikidata QID (e.g., {"https://datadistillery.wikibase.cloud/entity/Q4": "Q195562"}) |
required |
mash_client
|
Optional[Any]
|
Optional WikibaseLoader; if None, uses default |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Tuple of (charged_packet, notices) with: |
list[ConformanceNotice]
|
|
tuple[dict[str, Any], list[ConformanceNotice]]
|
|
Source code in gkc/still_charger.py
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 | |
charge_curation_packet
Fill packet entities with real source values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
packet
|
dict[str, Any]
|
Curation packet generated from profile scaffolds. |
required |
source_values
|
dict[str, dict[str, Any]]
|
Mapping keyed by entity ID, profile_entity URI, QID, or profile name.
Each value is expected to include a |
required |
specificationless
|
bool
|
When |
True
|
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], ChargeReport]
|
Tuple of (charged_packet, report). |
Source code in gkc/still_charger.py
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 | |