API Reference¶
Auto-generated code documentation.
civic_exchange_protocol ¶
Civic Exchange Protocol (CEP) - Python Implementation.
A protocol for transparent, verifiable civic data exchange.
Submodules
core: Core types (timestamps, hashes, attestations) core_linker: SNFEI generation and entity normalization entity: Entity records and identifiers relationship: Relationship records exchange: Exchange records
api ¶
CEP Entity Canonicalization Service.
This service generates the Canonical String and Entity Hash for a CEP Entity Record, enforcing strict field ordering and temporal rules.
Dependencies: fastapi, uvicorn, pydantic, hashlib, datetime, decimal To run: uvicorn cep_entity_service:app --reload
CanonicalResponse ¶
Bases: BaseModel
Defines the structure of the API's successful output.
Source code in src/python/src/civic_exchange_protocol/api.py
186 187 188 189 190 191 192 | |
EntityPayload ¶
Bases: BaseModel
Defines the structure for the CEP Entity Record.
Source code in src/python/src/civic_exchange_protocol/api.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
Config ¶
Pydantic model configuration for JSON serialization and schema examples.
Source code in src/python/src/civic_exchange_protocol/api.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
canonicalize_entity
async
¶
canonicalize_entity(payload: EntityPayload)
Receives an Entity Record, performs canonical serialization (CAOS), and returns the cryptographic entity hash.
Performs canonical serialization (CAOS) on the entity record.
Source code in src/python/src/civic_exchange_protocol/api.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
generate_canonical_string ¶
generate_canonical_string(data: EntityPayload) -> str
Generate the pipe-delimited Canonical String (C-String) based on CAOS.
Source code in src/python/src/civic_exchange_protocol/api.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
generate_entity_hash ¶
generate_entity_hash(c_string: str) -> str
Generate the final SHA-256 Entity Hash.
Source code in src/python/src/civic_exchange_protocol/api.py
172 173 174 | |
cli ¶
cli ¶
Command-line interface for the Civic Exchange Protocol.
This module provides CLI commands for: - version: Display the package version - validate: Validate exchange protocol data
validate ¶
validate()
Validate exchange protocol data.
Source code in src/python/src/civic_exchange_protocol/cli/cli.py
21 22 23 24 | |
version ¶
version()
Show package version.
Source code in src/python/src/civic_exchange_protocol/cli/cli.py
13 14 15 16 17 18 | |
core ¶
CEP Core - Core primitives for the Civic Exchange Protocol.
This package provides the foundational types used by all CEP record types:
- CanonicalTimestamp: Microsecond-precision UTC timestamps
- CanonicalHash: SHA-256 hash values
- Canonicalize: Base class for deterministic serialization
- Attestation: Cryptographic proof of record integrity
Attestation
dataclass
¶
Bases: Canonicalize
Cryptographic attestation proving record authenticity and integrity.
This structure aligns with W3C Verifiable Credentials Data Integrity.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields in alphabetical order.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
new
classmethod
¶
new(
attestor_id: str,
attestation_timestamp: CanonicalTimestamp,
proof_type: str,
proof_value: str,
verification_method_uri: str,
) -> Attestation
Create a new Attestation with required fields.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
with_anchor ¶
with_anchor(uri: str) -> Attestation
Return a new Attestation with the specified anchor URI.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
87 88 89 90 91 92 93 94 95 96 97 | |
with_purpose ¶
with_purpose(purpose: ProofPurpose) -> Attestation
Return a new Attestation with the specified proof purpose.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
75 76 77 78 79 80 81 82 83 84 85 | |
CanonicalHash ¶
A SHA-256 hash value represented as a 64-character lowercase hex string.
Source code in src/python/src/civic_exchange_protocol/core/hash.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
__eq__ ¶
__eq__(other: object) -> bool
Check equality with another CanonicalHash instance.
Source code in src/python/src/civic_exchange_protocol/core/hash.py
75 76 77 78 79 | |
__hash__ ¶
__hash__() -> int
Return a hash value for the CanonicalHash instance.
Source code in src/python/src/civic_exchange_protocol/core/hash.py
81 82 83 | |
__init__ ¶
__init__(hex_value: str) -> None
Create a CanonicalHash from a hex string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hex_value
|
str
|
A 64-character hexadecimal string. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the string is not valid. |
Source code in src/python/src/civic_exchange_protocol/core/hash.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
__repr__ ¶
__repr__() -> str
Return a detailed string representation of the hash.
Source code in src/python/src/civic_exchange_protocol/core/hash.py
71 72 73 | |
__str__ ¶
__str__() -> str
Return a string representation of the hash.
Source code in src/python/src/civic_exchange_protocol/core/hash.py
67 68 69 | |
as_bytes ¶
as_bytes() -> bytes
Return the hash as bytes (32 bytes).
Source code in src/python/src/civic_exchange_protocol/core/hash.py
63 64 65 | |
as_hex ¶
as_hex() -> str
Return the hash as a lowercase hex string.
Source code in src/python/src/civic_exchange_protocol/core/hash.py
59 60 61 | |
from_canonical_string
classmethod
¶
from_canonical_string(canonical: str) -> CanonicalHash
Compute the SHA-256 hash of the given canonical string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canonical
|
str
|
The canonical string to hash. |
required |
Returns:
| Type | Description |
|---|---|
CanonicalHash
|
A CanonicalHash instance. |
Source code in src/python/src/civic_exchange_protocol/core/hash.py
30 31 32 33 34 35 36 37 38 39 40 41 42 | |
from_hex
classmethod
¶
from_hex(hex_value: str) -> Optional[CanonicalHash]
Create a CanonicalHash from a pre-computed hex string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hex_value
|
str
|
A hexadecimal string. |
required |
Returns:
| Type | Description |
|---|---|
Optional[CanonicalHash]
|
A CanonicalHash instance, or None if invalid. |
Source code in src/python/src/civic_exchange_protocol/core/hash.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
CanonicalTimestamp ¶
A canonical CEP timestamp with mandatory microsecond precision.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
__eq__ ¶
__eq__(other: object) -> bool
Check equality with another CanonicalTimestamp.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
109 110 111 112 113 | |
__ge__ ¶
__ge__(other: CanonicalTimestamp) -> bool
Check if this timestamp is greater than or equal to another.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
133 134 135 136 137 | |
__gt__ ¶
__gt__(other: CanonicalTimestamp) -> bool
Check if this timestamp is greater than another.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
127 128 129 130 131 | |
__hash__ ¶
__hash__() -> int
Return the hash of the timestamp.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
139 140 141 | |
__init__ ¶
__init__(dt: datetime) -> None
Create a new CanonicalTimestamp from a datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
datetime
|
A datetime object. If naive, assumed to be UTC. If aware, will be converted to UTC. |
required |
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
22 23 24 25 26 27 28 29 30 31 32 33 34 | |
__le__ ¶
__le__(other: CanonicalTimestamp) -> bool
Check if this timestamp is less than or equal to another.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
121 122 123 124 125 | |
__lt__ ¶
__lt__(other: CanonicalTimestamp) -> bool
Check if this timestamp is less than another.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
115 116 117 118 119 | |
__repr__ ¶
__repr__() -> str
Return the developer-friendly representation of the timestamp.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
105 106 107 | |
__str__ ¶
__str__() -> str
Return the canonical string representation of the timestamp.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
101 102 103 | |
as_datetime ¶
as_datetime() -> datetime
Return the underlying datetime object (UTC).
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
88 89 90 | |
now
classmethod
¶
now() -> CanonicalTimestamp
Return the current UTC time as a CanonicalTimestamp.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
36 37 38 39 | |
parse
classmethod
¶
parse(s: str) -> CanonicalTimestamp
Parse an ISO 8601 timestamp string.
Accepts formats: - 2025-11-28T14:30:00.123456Z - 2025-11-28T14:30:00.123456+00:00 - 2025-11-28T14:30:00Z (will add .000000)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
The timestamp string to parse. |
required |
Returns:
| Type | Description |
|---|---|
CanonicalTimestamp
|
A CanonicalTimestamp instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the string cannot be parsed. |
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
to_canonical_string ¶
to_canonical_string() -> str
Return the canonical string representation.
Format: YYYY-MM-DDTHH:MM:SS.ffffffZ
This format is REQUIRED for hash stability across all CEP implementations.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
92 93 94 95 96 97 98 99 | |
Canonicalize ¶
Bases: ABC
Base class for types that can be serialized to a canonical string for hashing.
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
calculate_hash ¶
calculate_hash() -> CanonicalHash
Compute the SHA-256 hash of the canonical string.
Returns:
| Type | Description |
|---|---|
CanonicalHash
|
A CanonicalHash instance. |
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
57 58 59 60 61 62 63 | |
canonical_fields
abstractmethod
¶
canonical_fields() -> dict[str, str]
Return the ordered map of field names to their canonical string values.
Fields with None/null/empty values should NOT be included in the dict. The dict will be sorted alphabetically by key.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A dictionary of field names to string values. |
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
29 30 31 32 33 34 35 36 37 38 39 | |
to_canonical_string ¶
to_canonical_string() -> str
Generate the canonical string representation for hashing.
Format: "field1":"value1","field2":"value2",...
Fields are ordered alphabetically by key.
Returns:
| Type | Description |
|---|---|
str
|
The canonical string. |
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
CepError ¶
Bases: Exception
Base exception for CEP operations.
Source code in src/python/src/civic_exchange_protocol/core/error.py
4 5 6 7 | |
HashMismatchError ¶
Bases: CepError
Hash verification failed.
Source code in src/python/src/civic_exchange_protocol/core/error.py
50 51 52 53 54 55 56 57 | |
__init__ ¶
__init__(expected: str, actual: str) -> None
Initialize with expected and actual hash values.
Source code in src/python/src/civic_exchange_protocol/core/error.py
53 54 55 56 57 | |
InvalidHashError ¶
Bases: CepError
Invalid hash format.
Source code in src/python/src/civic_exchange_protocol/core/error.py
18 19 20 21 22 23 | |
__init__ ¶
__init__(value: str) -> None
Initialize with the invalid hash value.
Source code in src/python/src/civic_exchange_protocol/core/error.py
21 22 23 | |
InvalidIdentifierError ¶
Bases: CepError
Invalid identifier format.
Source code in src/python/src/civic_exchange_protocol/core/error.py
26 27 28 29 30 31 | |
__init__ ¶
__init__(message: str) -> None
Initialize with error message about invalid identifier.
Source code in src/python/src/civic_exchange_protocol/core/error.py
29 30 31 | |
InvalidTimestampError ¶
Bases: CepError
Invalid timestamp format.
Source code in src/python/src/civic_exchange_protocol/core/error.py
10 11 12 13 14 15 | |
__init__ ¶
__init__(message: str) -> None
Initialize with error message about invalid timestamp.
Source code in src/python/src/civic_exchange_protocol/core/error.py
13 14 15 | |
MissingFieldError ¶
Bases: CepError
Missing required field.
Source code in src/python/src/civic_exchange_protocol/core/error.py
34 35 36 37 38 39 | |
__init__ ¶
__init__(field: str) -> None
Initialize with the name of the missing field.
Source code in src/python/src/civic_exchange_protocol/core/error.py
37 38 39 | |
ProofPurpose ¶
Bases: Enum
The purpose of a cryptographic proof.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
16 17 18 19 20 21 22 23 24 25 | |
as_str ¶
as_str() -> str
Return the canonical string representation.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
23 24 25 | |
RevisionChainError ¶
Bases: CepError
Revision chain error.
Source code in src/python/src/civic_exchange_protocol/core/error.py
60 61 62 63 64 65 | |
__init__ ¶
__init__(message: str) -> None
Initialize with error message about revision chain.
Source code in src/python/src/civic_exchange_protocol/core/error.py
63 64 65 | |
UnsupportedVersionError ¶
Bases: CepError
Schema version mismatch.
Source code in src/python/src/civic_exchange_protocol/core/error.py
42 43 44 45 46 47 | |
__init__ ¶
__init__(version: str) -> None
Initialize with the unsupported version string.
Source code in src/python/src/civic_exchange_protocol/core/error.py
45 46 47 | |
format_amount ¶
format_amount(amount: float) -> str
Format a monetary amount with exactly 2 decimal places.
This ensures consistent formatting across all implementations: - 100 becomes "100.00" - 100.5 becomes "100.50" - 100.756 becomes "100.76" (rounded)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float
|
The monetary amount. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formatted string with exactly 2 decimal places. |
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
insert_if_present ¶
insert_if_present(
fields: dict[str, str], key: str, value: str | None
) -> None
Add a field to the dict only if the value is not None and not empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
dict[str, str]
|
The dictionary to add to. |
required |
key
|
str
|
The field name. |
required |
value
|
str | None
|
The field value (may be None or empty). |
required |
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
86 87 88 89 90 91 92 93 94 95 | |
insert_required ¶
insert_required(
fields: dict[str, str], key: str, value: str
) -> None
Add a required field to the dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
dict[str, str]
|
The dictionary to add to. |
required |
key
|
str
|
The field name. |
required |
value
|
str
|
The field value. |
required |
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
98 99 100 101 102 103 104 105 106 | |
attestation ¶
Attestation and cryptographic proof types for CEP records.
Every CEP record includes an attestation block that proves: - Who attested to the record (attestor_id) - When it was attested (attestation_timestamp) - Cryptographic proof of integrity (proof_type, proof_value, verification_method_uri)
Attestation
dataclass
¶
Bases: Canonicalize
Cryptographic attestation proving record authenticity and integrity.
This structure aligns with W3C Verifiable Credentials Data Integrity.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields in alphabetical order.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
new
classmethod
¶
new(
attestor_id: str,
attestation_timestamp: CanonicalTimestamp,
proof_type: str,
proof_value: str,
verification_method_uri: str,
) -> Attestation
Create a new Attestation with required fields.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
with_anchor ¶
with_anchor(uri: str) -> Attestation
Return a new Attestation with the specified anchor URI.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
87 88 89 90 91 92 93 94 95 96 97 | |
with_purpose ¶
with_purpose(purpose: ProofPurpose) -> Attestation
Return a new Attestation with the specified proof purpose.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
75 76 77 78 79 80 81 82 83 84 85 | |
ProofPurpose ¶
Bases: Enum
The purpose of a cryptographic proof.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
16 17 18 19 20 21 22 23 24 25 | |
as_str ¶
as_str() -> str
Return the canonical string representation.
Source code in src/python/src/civic_exchange_protocol/core/attestation.py
23 24 25 | |
canonical ¶
Canonical serialization for CEP records.
This module provides the base class and utilities for generating deterministic canonical strings from CEP records. The canonical string is the input to SHA-256 hashing for record integrity verification.
Canonicalization Rules: 1. Field Order: Fields MUST be serialized in alphabetical order. 2. Null/Empty Omission: Fields with None or empty string values MUST be omitted entirely from the canonical string. 3. Timestamp Format: All timestamps MUST use YYYY-MM-DDTHH:MM:SS.ffffffZ with exactly 6 decimal places for microseconds. 4. Numeric Format: Monetary amounts MUST use exactly 2 decimal places. Integers MUST NOT have decimal points. 5. String Escaping: Strings are NOT JSON-escaped in the canonical form. The canonical string is a simple key:value concatenation. 6. Encoding: The canonical string MUST be UTF-8 encoded.
Canonicalize ¶
Bases: ABC
Base class for types that can be serialized to a canonical string for hashing.
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
calculate_hash ¶
calculate_hash() -> CanonicalHash
Compute the SHA-256 hash of the canonical string.
Returns:
| Type | Description |
|---|---|
CanonicalHash
|
A CanonicalHash instance. |
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
57 58 59 60 61 62 63 | |
canonical_fields
abstractmethod
¶
canonical_fields() -> dict[str, str]
Return the ordered map of field names to their canonical string values.
Fields with None/null/empty values should NOT be included in the dict. The dict will be sorted alphabetically by key.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A dictionary of field names to string values. |
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
29 30 31 32 33 34 35 36 37 38 39 | |
to_canonical_string ¶
to_canonical_string() -> str
Generate the canonical string representation for hashing.
Format: "field1":"value1","field2":"value2",...
Fields are ordered alphabetically by key.
Returns:
| Type | Description |
|---|---|
str
|
The canonical string. |
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
format_amount ¶
format_amount(amount: float) -> str
Format a monetary amount with exactly 2 decimal places.
This ensures consistent formatting across all implementations: - 100 becomes "100.00" - 100.5 becomes "100.50" - 100.756 becomes "100.76" (rounded)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float
|
The monetary amount. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formatted string with exactly 2 decimal places. |
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
insert_if_present ¶
insert_if_present(
fields: dict[str, str], key: str, value: str | None
) -> None
Add a field to the dict only if the value is not None and not empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
dict[str, str]
|
The dictionary to add to. |
required |
key
|
str
|
The field name. |
required |
value
|
str | None
|
The field value (may be None or empty). |
required |
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
86 87 88 89 90 91 92 93 94 95 | |
insert_required ¶
insert_required(
fields: dict[str, str], key: str, value: str
) -> None
Add a required field to the dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
dict[str, str]
|
The dictionary to add to. |
required |
key
|
str
|
The field name. |
required |
value
|
str
|
The field value. |
required |
Source code in src/python/src/civic_exchange_protocol/core/canonical.py
98 99 100 101 102 103 104 105 106 | |
error ¶
Error types for CEP operations.
CepError ¶
Bases: Exception
Base exception for CEP operations.
Source code in src/python/src/civic_exchange_protocol/core/error.py
4 5 6 7 | |
HashMismatchError ¶
Bases: CepError
Hash verification failed.
Source code in src/python/src/civic_exchange_protocol/core/error.py
50 51 52 53 54 55 56 57 | |
__init__ ¶
__init__(expected: str, actual: str) -> None
Initialize with expected and actual hash values.
Source code in src/python/src/civic_exchange_protocol/core/error.py
53 54 55 56 57 | |
InvalidHashError ¶
Bases: CepError
Invalid hash format.
Source code in src/python/src/civic_exchange_protocol/core/error.py
18 19 20 21 22 23 | |
__init__ ¶
__init__(value: str) -> None
Initialize with the invalid hash value.
Source code in src/python/src/civic_exchange_protocol/core/error.py
21 22 23 | |
InvalidIdentifierError ¶
Bases: CepError
Invalid identifier format.
Source code in src/python/src/civic_exchange_protocol/core/error.py
26 27 28 29 30 31 | |
__init__ ¶
__init__(message: str) -> None
Initialize with error message about invalid identifier.
Source code in src/python/src/civic_exchange_protocol/core/error.py
29 30 31 | |
InvalidTimestampError ¶
Bases: CepError
Invalid timestamp format.
Source code in src/python/src/civic_exchange_protocol/core/error.py
10 11 12 13 14 15 | |
__init__ ¶
__init__(message: str) -> None
Initialize with error message about invalid timestamp.
Source code in src/python/src/civic_exchange_protocol/core/error.py
13 14 15 | |
MissingFieldError ¶
Bases: CepError
Missing required field.
Source code in src/python/src/civic_exchange_protocol/core/error.py
34 35 36 37 38 39 | |
__init__ ¶
__init__(field: str) -> None
Initialize with the name of the missing field.
Source code in src/python/src/civic_exchange_protocol/core/error.py
37 38 39 | |
RevisionChainError ¶
Bases: CepError
Revision chain error.
Source code in src/python/src/civic_exchange_protocol/core/error.py
60 61 62 63 64 65 | |
__init__ ¶
__init__(message: str) -> None
Initialize with error message about revision chain.
Source code in src/python/src/civic_exchange_protocol/core/error.py
63 64 65 | |
UnsupportedVersionError ¶
Bases: CepError
Schema version mismatch.
Source code in src/python/src/civic_exchange_protocol/core/error.py
42 43 44 45 46 47 | |
__init__ ¶
__init__(version: str) -> None
Initialize with the unsupported version string.
Source code in src/python/src/civic_exchange_protocol/core/error.py
45 46 47 | |
hash ¶
Cryptographic hashing utilities for CEP records.
All CEP hashes are SHA-256, represented as lowercase hexadecimal strings.
CanonicalHash ¶
A SHA-256 hash value represented as a 64-character lowercase hex string.
Source code in src/python/src/civic_exchange_protocol/core/hash.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
__eq__ ¶
__eq__(other: object) -> bool
Check equality with another CanonicalHash instance.
Source code in src/python/src/civic_exchange_protocol/core/hash.py
75 76 77 78 79 | |
__hash__ ¶
__hash__() -> int
Return a hash value for the CanonicalHash instance.
Source code in src/python/src/civic_exchange_protocol/core/hash.py
81 82 83 | |
__init__ ¶
__init__(hex_value: str) -> None
Create a CanonicalHash from a hex string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hex_value
|
str
|
A 64-character hexadecimal string. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the string is not valid. |
Source code in src/python/src/civic_exchange_protocol/core/hash.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
__repr__ ¶
__repr__() -> str
Return a detailed string representation of the hash.
Source code in src/python/src/civic_exchange_protocol/core/hash.py
71 72 73 | |
__str__ ¶
__str__() -> str
Return a string representation of the hash.
Source code in src/python/src/civic_exchange_protocol/core/hash.py
67 68 69 | |
as_bytes ¶
as_bytes() -> bytes
Return the hash as bytes (32 bytes).
Source code in src/python/src/civic_exchange_protocol/core/hash.py
63 64 65 | |
as_hex ¶
as_hex() -> str
Return the hash as a lowercase hex string.
Source code in src/python/src/civic_exchange_protocol/core/hash.py
59 60 61 | |
from_canonical_string
classmethod
¶
from_canonical_string(canonical: str) -> CanonicalHash
Compute the SHA-256 hash of the given canonical string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canonical
|
str
|
The canonical string to hash. |
required |
Returns:
| Type | Description |
|---|---|
CanonicalHash
|
A CanonicalHash instance. |
Source code in src/python/src/civic_exchange_protocol/core/hash.py
30 31 32 33 34 35 36 37 38 39 40 41 42 | |
from_hex
classmethod
¶
from_hex(hex_value: str) -> Optional[CanonicalHash]
Create a CanonicalHash from a pre-computed hex string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hex_value
|
str
|
A hexadecimal string. |
required |
Returns:
| Type | Description |
|---|---|
Optional[CanonicalHash]
|
A CanonicalHash instance, or None if invalid. |
Source code in src/python/src/civic_exchange_protocol/core/hash.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
timestamp ¶
Canonical timestamp handling for CEP records.
All CEP timestamps MUST be: - UTC timezone (indicated by 'Z' suffix) - ISO 8601 format - Microsecond precision (exactly 6 decimal places)
Example: 2025-11-28T14:30:00.000000Z
CanonicalTimestamp ¶
A canonical CEP timestamp with mandatory microsecond precision.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
__eq__ ¶
__eq__(other: object) -> bool
Check equality with another CanonicalTimestamp.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
109 110 111 112 113 | |
__ge__ ¶
__ge__(other: CanonicalTimestamp) -> bool
Check if this timestamp is greater than or equal to another.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
133 134 135 136 137 | |
__gt__ ¶
__gt__(other: CanonicalTimestamp) -> bool
Check if this timestamp is greater than another.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
127 128 129 130 131 | |
__hash__ ¶
__hash__() -> int
Return the hash of the timestamp.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
139 140 141 | |
__init__ ¶
__init__(dt: datetime) -> None
Create a new CanonicalTimestamp from a datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
datetime
|
A datetime object. If naive, assumed to be UTC. If aware, will be converted to UTC. |
required |
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
22 23 24 25 26 27 28 29 30 31 32 33 34 | |
__le__ ¶
__le__(other: CanonicalTimestamp) -> bool
Check if this timestamp is less than or equal to another.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
121 122 123 124 125 | |
__lt__ ¶
__lt__(other: CanonicalTimestamp) -> bool
Check if this timestamp is less than another.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
115 116 117 118 119 | |
__repr__ ¶
__repr__() -> str
Return the developer-friendly representation of the timestamp.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
105 106 107 | |
__str__ ¶
__str__() -> str
Return the canonical string representation of the timestamp.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
101 102 103 | |
as_datetime ¶
as_datetime() -> datetime
Return the underlying datetime object (UTC).
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
88 89 90 | |
now
classmethod
¶
now() -> CanonicalTimestamp
Return the current UTC time as a CanonicalTimestamp.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
36 37 38 39 | |
parse
classmethod
¶
parse(s: str) -> CanonicalTimestamp
Parse an ISO 8601 timestamp string.
Accepts formats: - 2025-11-28T14:30:00.123456Z - 2025-11-28T14:30:00.123456+00:00 - 2025-11-28T14:30:00Z (will add .000000)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
The timestamp string to parse. |
required |
Returns:
| Type | Description |
|---|---|
CanonicalTimestamp
|
A CanonicalTimestamp instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the string cannot be parsed. |
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
to_canonical_string ¶
to_canonical_string() -> str
Return the canonical string representation.
Format: YYYY-MM-DDTHH:MM:SS.ffffffZ
This format is REQUIRED for hash stability across all CEP implementations.
Source code in src/python/src/civic_exchange_protocol/core/timestamp.py
92 93 94 95 96 97 98 99 | |
entity ¶
CEP Entity - Entity records for the Civic Exchange Protocol.
This package defines the EntityRecord type, which represents a verified civic entity. Entities are the foundational primitive in CEP—all relationships and exchanges reference attested entities.
AdditionalScheme
dataclass
¶
An additional identifier scheme not explicitly defined in the schema.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
111 112 113 114 115 116 | |
CanadianBn
dataclass
¶
Canadian Business Number with program account.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
__post_init__ ¶
__post_init__() -> None
Validate the Canadian BN format after initialization.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
83 84 85 86 | |
as_str ¶
as_str() -> str
Return the Canadian BN as a string.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
106 107 108 | |
new
classmethod
¶
new(value: str) -> Optional[CanadianBn]
Create a new Canadian BN, returning None if invalid.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
98 99 100 101 102 103 104 | |
EntityIdentifiers
dataclass
¶
Bases: Canonicalize
Collection of all known identifiers for an entity.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields in alphabetical order.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
has_any ¶
has_any() -> bool
Return True if at least one identifier is present.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
159 160 161 162 163 164 165 166 167 | |
primary_identifier ¶
primary_identifier() -> str | None
Return the 'best' identifier for use as the verifiable ID.
Priority: LEI > SAM UEI > SNFEI > Canadian BN > first additional
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
with_lei ¶
with_lei(lei: Lei) -> EntityIdentifiers
Return a new EntityIdentifiers with the LEI set.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
139 140 141 142 143 144 145 146 147 | |
with_sam_uei ¶
with_sam_uei(uei: SamUei) -> EntityIdentifiers
Return a new EntityIdentifiers with the SAM UEI set.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
129 130 131 132 133 134 135 136 137 | |
with_snfei ¶
with_snfei(snfei: Snfei) -> EntityIdentifiers
Return a new EntityIdentifiers with the SNFEI set.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
149 150 151 152 153 154 155 156 157 | |
EntityRecord
dataclass
¶
Bases: Canonicalize
A complete CEP Entity Record.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields in alphabetical order.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
new
classmethod
¶
new(
verifiable_id: str,
identifiers: EntityIdentifiers,
legal_name: str,
jurisdiction_iso: str,
status: EntityStatus,
attestation: Attestation,
) -> EntityRecord
Create a new EntityRecord with required fields.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
validate ¶
validate() -> None
Validate that the record has all required fields properly set.
Raises:
| Type | Description |
|---|---|
ValueError
|
If validation fails. |
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
with_entity_type ¶
with_entity_type(uri: str) -> EntityRecord
Return a new EntityRecord with the entity type URI set.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
with_naics ¶
with_naics(code: str) -> EntityRecord
Return a new EntityRecord with the NAICS code set.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
with_normalized_name ¶
with_normalized_name(name: str) -> EntityRecord
Return a new EntityRecord with the normalized name set.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
with_previous_hash ¶
with_previous_hash(hash_val: CanonicalHash) -> EntityRecord
Return a new EntityRecord with the previous hash set.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
with_resolution_confidence ¶
with_resolution_confidence(
confidence: ResolutionConfidence,
) -> EntityRecord
Return a new EntityRecord with resolution confidence set.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
with_revision ¶
with_revision(revision: int) -> EntityRecord
Return a new EntityRecord with the revision number set.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
EntityStatus
dataclass
¶
Bases: Canonicalize
Entity status information.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields for entity status.
dict[str, str] A dictionary containing the canonical representation of status fields.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
52 53 54 55 56 57 58 59 60 61 62 63 64 | |
EntityStatusCode ¶
Bases: Enum
Entity operational status.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
as_str ¶
as_str() -> str
Return the string representation of the status code.
Returns:¶
str The status code value as a string.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
32 33 34 35 36 37 38 39 40 | |
Lei
dataclass
¶
Legal Entity Identifier per ISO 17442 (20 alphanumeric characters).
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
__post_init__ ¶
__post_init__() -> None
Validate the LEI format after initialization.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
55 56 57 58 | |
as_str ¶
as_str() -> str
Return the LEI as a string.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
72 73 74 | |
new
classmethod
¶
new(value: str) -> Optional[Lei]
Create a new LEI, returning None if invalid.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
64 65 66 67 68 69 70 | |
ResolutionConfidence
dataclass
¶
Bases: Canonicalize
Entity resolution confidence metadata.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields for resolution confidence.
Returns:¶
dict[str, str] A dictionary containing the canonical representation of resolution confidence fields.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
SamUei
dataclass
¶
SAM.gov Unique Entity Identifier (12 alphanumeric characters).
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
__post_init__ ¶
__post_init__() -> None
Validate the SAM UEI format after initialization.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
25 26 27 28 | |
as_str ¶
as_str() -> str
Return the SAM UEI as a string.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
44 45 46 | |
new
classmethod
¶
new(value: str) -> Optional[SamUei]
Create a new SAM UEI, returning None if invalid.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
36 37 38 39 40 41 42 | |
Snfei
dataclass
¶
A validated SNFEI (64-character lowercase hex string).
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
__post_init__ ¶
__post_init__() -> None
Validate SNFEI format after initialization.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
32 33 34 35 36 37 | |
__repr__ ¶
__repr__() -> str
Return abbreviated representation of SNFEI.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
43 44 45 | |
__str__ ¶
__str__() -> str
Return string representation of SNFEI.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
39 40 41 | |
as_str ¶
as_str() -> str
Return the hash value (for API compatibility).
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
47 48 49 | |
short ¶
short(length: int = 12) -> str
Return a shortened version for display.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
51 52 53 | |
entity ¶
CEP Entity Record definition.
The Entity Record is the foundational primitive in CEP. It represents a verified civic entity (government agency, contractor, nonprofit, individual). All relationships and exchanges reference attested entities.
EntityRecord
dataclass
¶
Bases: Canonicalize
A complete CEP Entity Record.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields in alphabetical order.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
new
classmethod
¶
new(
verifiable_id: str,
identifiers: EntityIdentifiers,
legal_name: str,
jurisdiction_iso: str,
status: EntityStatus,
attestation: Attestation,
) -> EntityRecord
Create a new EntityRecord with required fields.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
validate ¶
validate() -> None
Validate that the record has all required fields properly set.
Raises:
| Type | Description |
|---|---|
ValueError
|
If validation fails. |
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
with_entity_type ¶
with_entity_type(uri: str) -> EntityRecord
Return a new EntityRecord with the entity type URI set.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
with_naics ¶
with_naics(code: str) -> EntityRecord
Return a new EntityRecord with the NAICS code set.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
with_normalized_name ¶
with_normalized_name(name: str) -> EntityRecord
Return a new EntityRecord with the normalized name set.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
with_previous_hash ¶
with_previous_hash(hash_val: CanonicalHash) -> EntityRecord
Return a new EntityRecord with the previous hash set.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
with_resolution_confidence ¶
with_resolution_confidence(
confidence: ResolutionConfidence,
) -> EntityRecord
Return a new EntityRecord with resolution confidence set.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
with_revision ¶
with_revision(revision: int) -> EntityRecord
Return a new EntityRecord with the revision number set.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
EntityStatus
dataclass
¶
Bases: Canonicalize
Entity status information.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields for entity status.
dict[str, str] A dictionary containing the canonical representation of status fields.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
52 53 54 55 56 57 58 59 60 61 62 63 64 | |
EntityStatusCode ¶
Bases: Enum
Entity operational status.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
as_str ¶
as_str() -> str
Return the string representation of the status code.
Returns:¶
str The status code value as a string.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
32 33 34 35 36 37 38 39 40 | |
ResolutionConfidence
dataclass
¶
Bases: Canonicalize
Entity resolution confidence metadata.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields for resolution confidence.
Returns:¶
dict[str, str] A dictionary containing the canonical representation of resolution confidence fields.
Source code in src/python/src/civic_exchange_protocol/entity/entity.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
identifiers ¶
Entity identifier types for CEP.
CEP supports multiple identifier schemes organized into tiers:
- Tier 1 (Global): LEI (Legal Entity Identifier)
- Tier 2 (Federal): SAM.gov UEI
- Tier 3 (Sub-National): SNFEI (generated hash-based identifier)
- Extended: Canadian BN, UK Companies House, etc.
AdditionalScheme
dataclass
¶
An additional identifier scheme not explicitly defined in the schema.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
111 112 113 114 115 116 | |
CanadianBn
dataclass
¶
Canadian Business Number with program account.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
__post_init__ ¶
__post_init__() -> None
Validate the Canadian BN format after initialization.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
83 84 85 86 | |
as_str ¶
as_str() -> str
Return the Canadian BN as a string.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
106 107 108 | |
new
classmethod
¶
new(value: str) -> Optional[CanadianBn]
Create a new Canadian BN, returning None if invalid.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
98 99 100 101 102 103 104 | |
EntityIdentifiers
dataclass
¶
Bases: Canonicalize
Collection of all known identifiers for an entity.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields in alphabetical order.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
has_any ¶
has_any() -> bool
Return True if at least one identifier is present.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
159 160 161 162 163 164 165 166 167 | |
primary_identifier ¶
primary_identifier() -> str | None
Return the 'best' identifier for use as the verifiable ID.
Priority: LEI > SAM UEI > SNFEI > Canadian BN > first additional
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
with_lei ¶
with_lei(lei: Lei) -> EntityIdentifiers
Return a new EntityIdentifiers with the LEI set.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
139 140 141 142 143 144 145 146 147 | |
with_sam_uei ¶
with_sam_uei(uei: SamUei) -> EntityIdentifiers
Return a new EntityIdentifiers with the SAM UEI set.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
129 130 131 132 133 134 135 136 137 | |
with_snfei ¶
with_snfei(snfei: Snfei) -> EntityIdentifiers
Return a new EntityIdentifiers with the SNFEI set.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
149 150 151 152 153 154 155 156 157 | |
Lei
dataclass
¶
Legal Entity Identifier per ISO 17442 (20 alphanumeric characters).
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
__post_init__ ¶
__post_init__() -> None
Validate the LEI format after initialization.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
55 56 57 58 | |
as_str ¶
as_str() -> str
Return the LEI as a string.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
72 73 74 | |
new
classmethod
¶
new(value: str) -> Optional[Lei]
Create a new LEI, returning None if invalid.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
64 65 66 67 68 69 70 | |
SamUei
dataclass
¶
SAM.gov Unique Entity Identifier (12 alphanumeric characters).
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
__post_init__ ¶
__post_init__() -> None
Validate the SAM UEI format after initialization.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
25 26 27 28 | |
as_str ¶
as_str() -> str
Return the SAM UEI as a string.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
44 45 46 | |
new
classmethod
¶
new(value: str) -> Optional[SamUei]
Create a new SAM UEI, returning None if invalid.
Source code in src/python/src/civic_exchange_protocol/entity/identifiers.py
36 37 38 39 40 41 42 | |
exchange ¶
CEP Exchange - Exchange records for the Civic Exchange Protocol.
This package defines the ExchangeRecord type, which represents a verifiable value exchange (financial, in-kind, or informational) between entities within an established relationship. This is the atomic unit of civic transparency.
ExchangeCategorization
dataclass
¶
Bases: Canonicalize
Categorization codes for reporting and analysis.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields for the exchange categorization.
Returns:¶
dict[str, str] A dictionary containing the canonical field names and values.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
has_any ¶
has_any() -> bool
Return True if any categorization is present.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
166 167 168 169 170 171 172 173 | |
with_cfda ¶
with_cfda(cfda: str) -> ExchangeCategorization
Return a new ExchangeCategorization with CFDA set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
126 127 128 129 130 131 132 133 134 | |
with_gtas ¶
with_gtas(gtas: str) -> ExchangeCategorization
Return a new ExchangeCategorization with GTAS set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
146 147 148 149 150 151 152 153 154 | |
with_local_category ¶
with_local_category(
code: str, label: str
) -> ExchangeCategorization
Return a new ExchangeCategorization with local category set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
156 157 158 159 160 161 162 163 164 | |
with_naics ¶
with_naics(naics: str) -> ExchangeCategorization
Return a new ExchangeCategorization with NAICS set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
136 137 138 139 140 141 142 143 144 | |
ExchangeParty
dataclass
¶
Bases: Canonicalize
A party in an exchange (source or recipient).
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical representation of this party as a dictionary.
Returns:¶
dict[str, str] A dictionary containing the canonical fields for this exchange party.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
117 118 119 120 121 122 123 124 125 126 127 128 129 | |
with_account ¶
with_account(account: str) -> ExchangeParty
Return a new ExchangeParty with account identifier set.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
109 110 111 112 113 114 115 | |
with_role ¶
with_role(role_uri: str) -> ExchangeParty
Return a new ExchangeParty with role set.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
101 102 103 104 105 106 107 | |
ExchangeRecord
dataclass
¶
Bases: Canonicalize
A complete CEP Exchange Record.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields in alphabetical order.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
new
classmethod
¶
new(
verifiable_id: str,
relationship_id: str,
exchange_type_uri: str,
source_entity: ExchangeParty,
recipient_entity: ExchangeParty,
value: ExchangeValue,
occurred_timestamp: CanonicalTimestamp,
status: ExchangeStatus,
attestation: Attestation,
) -> ExchangeRecord
Create a new ExchangeRecord with required fields.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
with_categorization ¶
with_categorization(
cat: ExchangeCategorization,
) -> ExchangeRecord
Return a new ExchangeRecord with categorization set.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
with_previous_hash ¶
with_previous_hash(
hash_val: CanonicalHash,
) -> ExchangeRecord
Return a new ExchangeRecord with previous hash set.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
with_provenance ¶
with_provenance(chain: ProvenanceChain) -> ExchangeRecord
Return a new ExchangeRecord with provenance chain set.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
with_revision ¶
with_revision(revision: int) -> ExchangeRecord
Return a new ExchangeRecord with revision number set.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
with_source_reference ¶
with_source_reference(
reference: SourceReference,
) -> ExchangeRecord
Return a new ExchangeRecord with a source reference added.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
ExchangeStatus
dataclass
¶
Bases: Canonicalize
Exchange status information.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical field representation of the exchange status.
Returns:¶
dict[str, str] Dictionary containing the canonical fields.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
ExchangeStatusCode ¶
Bases: Enum
Exchange operational status.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
25 26 27 28 29 30 31 32 33 34 35 36 | |
as_str ¶
as_str() -> str
Return the string value of the exchange status code.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
34 35 36 | |
ExchangeValue
dataclass
¶
Bases: Canonicalize
The value being exchanged.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical representation of this value as a dictionary.
Returns:¶
dict[str, str] A dictionary containing the canonical fields for this exchange value.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
in_kind
classmethod
¶
in_kind(amount: float, description: str) -> ExchangeValue
Create an in-kind value with description.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
66 67 68 69 70 71 72 73 74 | |
monetary
classmethod
¶
monetary(
amount: float, currency_code: str = 'USD'
) -> ExchangeValue
Create a new monetary value.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
56 57 58 59 | |
usd
classmethod
¶
usd(amount: float) -> ExchangeValue
Create a new USD monetary value.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
61 62 63 64 | |
IntermediaryEntity
dataclass
¶
Bases: Canonicalize
An intermediary entity in the funding chain.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields for the intermediary entity.
Returns:¶
dict[str, str] A dictionary containing the canonical field names and values.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
23 24 25 26 27 28 29 30 31 32 33 34 | |
with_role ¶
with_role(role_uri: str) -> IntermediaryEntity
Return a new IntermediaryEntity with role set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
19 20 21 | |
ProvenanceChain
dataclass
¶
Bases: Canonicalize
Provenance chain tracing the flow of funds.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields for the provenance chain.
Returns:¶
dict[str, str] A dictionary containing the canonical field names and values.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
has_any ¶
has_any() -> bool
Return True if any provenance information is present.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
84 85 86 87 88 89 90 91 | |
with_funding_chain_tag ¶
with_funding_chain_tag(tag: str) -> ProvenanceChain
Return a new ProvenanceChain with funding chain tag set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
46 47 48 49 50 51 52 53 | |
with_intermediary ¶
with_intermediary(
entity: IntermediaryEntity,
) -> ProvenanceChain
Return a new ProvenanceChain with an intermediary added.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
64 65 66 67 68 69 70 71 72 73 | |
with_parent_exchange ¶
with_parent_exchange(exchange_id: str) -> ProvenanceChain
Return a new ProvenanceChain with parent exchange set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
75 76 77 78 79 80 81 82 | |
with_ultimate_source ¶
with_ultimate_source(entity_id: str) -> ProvenanceChain
Return a new ProvenanceChain with ultimate source set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
55 56 57 58 59 60 61 62 | |
SourceReference
dataclass
¶
Bases: Canonicalize
Reference to an authoritative source record.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical field representation of the source reference.
Returns:¶
dict[str, str] Dictionary containing the canonical fields.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
72 73 74 75 76 77 78 79 80 81 82 83 84 | |
ValueType
dataclass
¶
The type of value being exchanged.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
in_kind
classmethod
¶
in_kind() -> ValueType
Return a ValueType for in-kind exchanges.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
29 30 31 32 33 34 | |
monetary
classmethod
¶
monetary() -> ValueType
Return a ValueType for monetary exchanges.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
22 23 24 25 26 27 | |
service_hours
classmethod
¶
service_hours() -> ValueType
Return a ValueType for service hours exchanges.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
36 37 38 39 40 41 | |
exchange ¶
CEP Exchange Record definition.
An Exchange Record represents a verifiable value exchange (financial, in-kind, or informational) between entities within an established relationship. This is the atomic unit of civic transparency.
ExchangeRecord
dataclass
¶
Bases: Canonicalize
A complete CEP Exchange Record.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields in alphabetical order.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
new
classmethod
¶
new(
verifiable_id: str,
relationship_id: str,
exchange_type_uri: str,
source_entity: ExchangeParty,
recipient_entity: ExchangeParty,
value: ExchangeValue,
occurred_timestamp: CanonicalTimestamp,
status: ExchangeStatus,
attestation: Attestation,
) -> ExchangeRecord
Create a new ExchangeRecord with required fields.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
with_categorization ¶
with_categorization(
cat: ExchangeCategorization,
) -> ExchangeRecord
Return a new ExchangeRecord with categorization set.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
with_previous_hash ¶
with_previous_hash(
hash_val: CanonicalHash,
) -> ExchangeRecord
Return a new ExchangeRecord with previous hash set.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
with_provenance ¶
with_provenance(chain: ProvenanceChain) -> ExchangeRecord
Return a new ExchangeRecord with provenance chain set.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
with_revision ¶
with_revision(revision: int) -> ExchangeRecord
Return a new ExchangeRecord with revision number set.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
with_source_reference ¶
with_source_reference(
reference: SourceReference,
) -> ExchangeRecord
Return a new ExchangeRecord with a source reference added.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
ExchangeStatus
dataclass
¶
Bases: Canonicalize
Exchange status information.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical field representation of the exchange status.
Returns:¶
dict[str, str] Dictionary containing the canonical fields.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
ExchangeStatusCode ¶
Bases: Enum
Exchange operational status.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
25 26 27 28 29 30 31 32 33 34 35 36 | |
as_str ¶
as_str() -> str
Return the string value of the exchange status code.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
34 35 36 | |
SourceReference
dataclass
¶
Bases: Canonicalize
Reference to an authoritative source record.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical field representation of the source reference.
Returns:¶
dict[str, str] Dictionary containing the canonical fields.
Source code in src/python/src/civic_exchange_protocol/exchange/exchange.py
72 73 74 75 76 77 78 79 80 81 82 83 84 | |
provenance ¶
Provenance chain tracking for CEP exchanges.
Traces the compositional flow of funds through the civic graph. This is the Category Theory morphism path implementation.
ExchangeCategorization
dataclass
¶
Bases: Canonicalize
Categorization codes for reporting and analysis.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields for the exchange categorization.
Returns:¶
dict[str, str] A dictionary containing the canonical field names and values.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
has_any ¶
has_any() -> bool
Return True if any categorization is present.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
166 167 168 169 170 171 172 173 | |
with_cfda ¶
with_cfda(cfda: str) -> ExchangeCategorization
Return a new ExchangeCategorization with CFDA set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
126 127 128 129 130 131 132 133 134 | |
with_gtas ¶
with_gtas(gtas: str) -> ExchangeCategorization
Return a new ExchangeCategorization with GTAS set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
146 147 148 149 150 151 152 153 154 | |
with_local_category ¶
with_local_category(
code: str, label: str
) -> ExchangeCategorization
Return a new ExchangeCategorization with local category set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
156 157 158 159 160 161 162 163 164 | |
with_naics ¶
with_naics(naics: str) -> ExchangeCategorization
Return a new ExchangeCategorization with NAICS set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
136 137 138 139 140 141 142 143 144 | |
IntermediaryEntity
dataclass
¶
Bases: Canonicalize
An intermediary entity in the funding chain.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields for the intermediary entity.
Returns:¶
dict[str, str] A dictionary containing the canonical field names and values.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
23 24 25 26 27 28 29 30 31 32 33 34 | |
with_role ¶
with_role(role_uri: str) -> IntermediaryEntity
Return a new IntermediaryEntity with role set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
19 20 21 | |
ProvenanceChain
dataclass
¶
Bases: Canonicalize
Provenance chain tracing the flow of funds.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields for the provenance chain.
Returns:¶
dict[str, str] A dictionary containing the canonical field names and values.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
has_any ¶
has_any() -> bool
Return True if any provenance information is present.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
84 85 86 87 88 89 90 91 | |
with_funding_chain_tag ¶
with_funding_chain_tag(tag: str) -> ProvenanceChain
Return a new ProvenanceChain with funding chain tag set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
46 47 48 49 50 51 52 53 | |
with_intermediary ¶
with_intermediary(
entity: IntermediaryEntity,
) -> ProvenanceChain
Return a new ProvenanceChain with an intermediary added.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
64 65 66 67 68 69 70 71 72 73 | |
with_parent_exchange ¶
with_parent_exchange(exchange_id: str) -> ProvenanceChain
Return a new ProvenanceChain with parent exchange set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
75 76 77 78 79 80 81 82 | |
with_ultimate_source ¶
with_ultimate_source(entity_id: str) -> ProvenanceChain
Return a new ProvenanceChain with ultimate source set.
Source code in src/python/src/civic_exchange_protocol/exchange/provenance.py
55 56 57 58 59 60 61 62 | |
value ¶
Value types for CEP exchanges.
Supports monetary values (with currency) and in-kind contributions.
ExchangeParty
dataclass
¶
Bases: Canonicalize
A party in an exchange (source or recipient).
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical representation of this party as a dictionary.
Returns:¶
dict[str, str] A dictionary containing the canonical fields for this exchange party.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
117 118 119 120 121 122 123 124 125 126 127 128 129 | |
with_account ¶
with_account(account: str) -> ExchangeParty
Return a new ExchangeParty with account identifier set.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
109 110 111 112 113 114 115 | |
with_role ¶
with_role(role_uri: str) -> ExchangeParty
Return a new ExchangeParty with role set.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
101 102 103 104 105 106 107 | |
ExchangeValue
dataclass
¶
Bases: Canonicalize
The value being exchanged.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical representation of this value as a dictionary.
Returns:¶
dict[str, str] A dictionary containing the canonical fields for this exchange value.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
in_kind
classmethod
¶
in_kind(amount: float, description: str) -> ExchangeValue
Create an in-kind value with description.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
66 67 68 69 70 71 72 73 74 | |
monetary
classmethod
¶
monetary(
amount: float, currency_code: str = 'USD'
) -> ExchangeValue
Create a new monetary value.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
56 57 58 59 | |
usd
classmethod
¶
usd(amount: float) -> ExchangeValue
Create a new USD monetary value.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
61 62 63 64 | |
ValueType
dataclass
¶
The type of value being exchanged.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
in_kind
classmethod
¶
in_kind() -> ValueType
Return a ValueType for in-kind exchanges.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
29 30 31 32 33 34 | |
monetary
classmethod
¶
monetary() -> ValueType
Return a ValueType for monetary exchanges.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
22 23 24 25 26 27 | |
service_hours
classmethod
¶
service_hours() -> ValueType
Return a ValueType for service hours exchanges.
Source code in src/python/src/civic_exchange_protocol/exchange/value.py
36 37 38 39 40 41 | |
relationship ¶
CEP Relationship - Relationship records for the Civic Exchange Protocol.
This package defines the RelationshipRecord type, which represents a verifiable legal or functional relationship between two or more attested entities.
BilateralParties
dataclass
¶
Bases: Canonicalize
Bilateral parties in a two-party relationship.
Source code in src/python/src/civic_exchange_protocol/relationship/bilateral.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical field representation of bilateral parties.
Returns:¶
dict[str, str] A dictionary containing the canonical fields with partyA and partyB.
Source code in src/python/src/civic_exchange_protocol/relationship/bilateral.py
41 42 43 44 45 46 47 48 49 50 51 52 53 | |
FinancialTerms
dataclass
¶
Bases: Canonicalize
Financial terms of a relationship.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical representation of financial terms fields.
Returns:¶
dict[str, str] Dictionary containing the canonical field representations.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
Member
dataclass
¶
Bases: Canonicalize
A member in a multilateral relationship.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical field representation of the member.
Returns:¶
dict[str, str] Dictionary containing entityId, roleUri, and optionally participationShare.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
with_share ¶
with_share(share: float) -> Member
Return a new Member with the participation share set.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
26 27 28 29 30 31 32 | |
MultilateralMembers ¶
Bases: Canonicalize
A collection of members in a multilateral relationship.
Members are automatically sorted by entity_id to ensure hash stability regardless of insertion order.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
__init__ ¶
__init__() -> None
Initialize an empty collection of multilateral relationship members.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
57 58 59 | |
__iter__ ¶
__iter__() -> Iterator[Member]
Iterate over members in sorted order by entity_id.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
73 74 75 | |
__len__ ¶
__len__() -> int
Return the number of members in the collection.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
69 70 71 | |
add ¶
add(member: Member) -> None
Add a member to the set.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
61 62 63 64 65 66 67 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
105 106 107 108 109 110 111 112 113 114 115 | |
is_empty ¶
is_empty() -> bool
Check if the collection has no members.
Returns:¶
bool True if the collection is empty, False otherwise.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
77 78 79 80 81 82 83 84 85 | |
validate_shares ¶
validate_shares() -> None
Validate that all participation shares sum to 1.0 (if present).
Raises:
| Type | Description |
|---|---|
ValueError
|
If validation fails. |
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
Party
dataclass
¶
Bases: Canonicalize
A party in a bilateral relationship.
Source code in src/python/src/civic_exchange_protocol/relationship/bilateral.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical field representation of the party.
Returns:¶
dict[str, str] A dictionary containing the canonical fields with entityId and roleUri.
Source code in src/python/src/civic_exchange_protocol/relationship/bilateral.py
20 21 22 23 24 25 26 27 28 29 30 31 | |
RelationshipRecord
dataclass
¶
Bases: Canonicalize
A complete CEP Relationship Record.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields in alphabetical order.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
new_bilateral
classmethod
¶
new_bilateral(
verifiable_id: str,
relationship_type_uri: str,
parties: BilateralParties,
effective_timestamp: CanonicalTimestamp,
status: RelationshipStatus,
jurisdiction_iso: str,
attestation: Attestation,
) -> RelationshipRecord
Create a new bilateral RelationshipRecord.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
new_multilateral
classmethod
¶
new_multilateral(
verifiable_id: str,
relationship_type_uri: str,
members: MultilateralMembers,
effective_timestamp: CanonicalTimestamp,
status: RelationshipStatus,
jurisdiction_iso: str,
attestation: Attestation,
) -> RelationshipRecord
Create a new multilateral RelationshipRecord.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
with_expiration ¶
with_expiration(
timestamp: CanonicalTimestamp,
) -> RelationshipRecord
Return a new RelationshipRecord with expiration timestamp set.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
with_financial_terms ¶
with_financial_terms(
terms: FinancialTerms,
) -> RelationshipRecord
Return a new RelationshipRecord with financial terms set.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
with_parent ¶
with_parent(parent_id: str) -> RelationshipRecord
Return a new RelationshipRecord with parent relationship set.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
with_previous_hash ¶
with_previous_hash(
hash_val: CanonicalHash,
) -> RelationshipRecord
Return a new RelationshipRecord with previous hash set.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
with_revision ¶
with_revision(revision: int) -> RelationshipRecord
Return a new RelationshipRecord with revision number set.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
with_source_reference ¶
with_source_reference(
reference: SourceReference,
) -> RelationshipRecord
Return a new RelationshipRecord with a source reference added.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
RelationshipStatus
dataclass
¶
Bases: Canonicalize
Relationship status information.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical representation of relationship status fields.
Returns:¶
dict[str, str] Dictionary containing the canonical field representations.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
RelationshipStatusCode ¶
Bases: Enum
Relationship operational status.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
29 30 31 32 33 34 35 36 37 38 39 40 41 | |
as_str ¶
as_str() -> str
Return the string value of the relationship status code.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
39 40 41 | |
SourceReference
dataclass
¶
Bases: Canonicalize
Reference to an authoritative source record.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical representation of source reference fields.
Returns:¶
dict[str, str] Dictionary containing the canonical field representations.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
102 103 104 105 106 107 108 109 110 111 112 113 114 | |
bilateral ¶
Bilateral party definitions for two-party relationships.
Bilateral relationships have clear directionality: - Party A: The initiating, granting, or contracting party - Party B: The receiving, performing, or beneficiary party
BilateralParties
dataclass
¶
Bases: Canonicalize
Bilateral parties in a two-party relationship.
Source code in src/python/src/civic_exchange_protocol/relationship/bilateral.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical field representation of bilateral parties.
Returns:¶
dict[str, str] A dictionary containing the canonical fields with partyA and partyB.
Source code in src/python/src/civic_exchange_protocol/relationship/bilateral.py
41 42 43 44 45 46 47 48 49 50 51 52 53 | |
Party
dataclass
¶
Bases: Canonicalize
A party in a bilateral relationship.
Source code in src/python/src/civic_exchange_protocol/relationship/bilateral.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical field representation of the party.
Returns:¶
dict[str, str] A dictionary containing the canonical fields with entityId and roleUri.
Source code in src/python/src/civic_exchange_protocol/relationship/bilateral.py
20 21 22 23 24 25 26 27 28 29 30 31 | |
multilateral ¶
Multilateral member definitions for n-ary relationships.
Multilateral relationships involve more than two parties, such as: - Consortia - Joint ventures - Board memberships
Members are sorted by entity_id to guarantee deterministic ordering for hash stability across all implementations.
Member
dataclass
¶
Bases: Canonicalize
A member in a multilateral relationship.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical field representation of the member.
Returns:¶
dict[str, str] Dictionary containing entityId, roleUri, and optionally participationShare.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
with_share ¶
with_share(share: float) -> Member
Return a new Member with the participation share set.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
26 27 28 29 30 31 32 | |
MultilateralMembers ¶
Bases: Canonicalize
A collection of members in a multilateral relationship.
Members are automatically sorted by entity_id to ensure hash stability regardless of insertion order.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
__init__ ¶
__init__() -> None
Initialize an empty collection of multilateral relationship members.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
57 58 59 | |
__iter__ ¶
__iter__() -> Iterator[Member]
Iterate over members in sorted order by entity_id.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
73 74 75 | |
__len__ ¶
__len__() -> int
Return the number of members in the collection.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
69 70 71 | |
add ¶
add(member: Member) -> None
Add a member to the set.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
61 62 63 64 65 66 67 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
105 106 107 108 109 110 111 112 113 114 115 | |
is_empty ¶
is_empty() -> bool
Check if the collection has no members.
Returns:¶
bool True if the collection is empty, False otherwise.
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
77 78 79 80 81 82 83 84 85 | |
validate_shares ¶
validate_shares() -> None
Validate that all participation shares sum to 1.0 (if present).
Raises:
| Type | Description |
|---|---|
ValueError
|
If validation fails. |
Source code in src/python/src/civic_exchange_protocol/relationship/multilateral.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
relationship ¶
CEP Relationship Record definition.
A Relationship Record represents a verifiable legal or functional relationship between two or more attested entities.
Relationships can be: - Bilateral: Two-party relationships with clear directionality (contracts, grants) - Multilateral: N-ary relationships (consortia, boards, joint ventures)
FinancialTerms
dataclass
¶
Bases: Canonicalize
Financial terms of a relationship.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical representation of financial terms fields.
Returns:¶
dict[str, str] Dictionary containing the canonical field representations.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
RelationshipRecord
dataclass
¶
Bases: Canonicalize
A complete CEP Relationship Record.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical fields in alphabetical order.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
new_bilateral
classmethod
¶
new_bilateral(
verifiable_id: str,
relationship_type_uri: str,
parties: BilateralParties,
effective_timestamp: CanonicalTimestamp,
status: RelationshipStatus,
jurisdiction_iso: str,
attestation: Attestation,
) -> RelationshipRecord
Create a new bilateral RelationshipRecord.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
new_multilateral
classmethod
¶
new_multilateral(
verifiable_id: str,
relationship_type_uri: str,
members: MultilateralMembers,
effective_timestamp: CanonicalTimestamp,
status: RelationshipStatus,
jurisdiction_iso: str,
attestation: Attestation,
) -> RelationshipRecord
Create a new multilateral RelationshipRecord.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
with_expiration ¶
with_expiration(
timestamp: CanonicalTimestamp,
) -> RelationshipRecord
Return a new RelationshipRecord with expiration timestamp set.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
with_financial_terms ¶
with_financial_terms(
terms: FinancialTerms,
) -> RelationshipRecord
Return a new RelationshipRecord with financial terms set.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
with_parent ¶
with_parent(parent_id: str) -> RelationshipRecord
Return a new RelationshipRecord with parent relationship set.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
with_previous_hash ¶
with_previous_hash(
hash_val: CanonicalHash,
) -> RelationshipRecord
Return a new RelationshipRecord with previous hash set.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
with_revision ¶
with_revision(revision: int) -> RelationshipRecord
Return a new RelationshipRecord with revision number set.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
with_source_reference ¶
with_source_reference(
reference: SourceReference,
) -> RelationshipRecord
Return a new RelationshipRecord with a source reference added.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
RelationshipStatus
dataclass
¶
Bases: Canonicalize
Relationship status information.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical representation of relationship status fields.
Returns:¶
dict[str, str] Dictionary containing the canonical field representations.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
RelationshipStatusCode ¶
Bases: Enum
Relationship operational status.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
29 30 31 32 33 34 35 36 37 38 39 40 41 | |
as_str ¶
as_str() -> str
Return the string value of the relationship status code.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
39 40 41 | |
SourceReference
dataclass
¶
Bases: Canonicalize
Reference to an authoritative source record.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
canonical_fields ¶
canonical_fields() -> dict[str, str]
Return the canonical representation of source reference fields.
Returns:¶
dict[str, str] Dictionary containing the canonical field representations.
Source code in src/python/src/civic_exchange_protocol/relationship/relationship.py
102 103 104 105 106 107 108 109 110 111 112 113 114 | |
snfei ¶
CEP Core Linker: Entity Resolution and SNFEI Generation.
This package implements the Normalizing Functor architecture for generating deterministic entity identifiers (SNFEIs) from heterogeneous source data.
Architecture
┌──────────────┐ ┌────────────────┐ ┌─────────────┐ │ Raw Entity │ │ Intermediate │ │ Canonical │ │ Data │───> │ Canonical │───> │ Entity │ │ │ L │ │ N │ │ └──────────────┘ └────────────────┘ └─────────────┘ │ │ SHA-256 V ┌──────────────┐ │ SNFEI │ │ (64-char) │ └──────────────┘
L = Localization Functor (jurisdiction-specific transforms) N = Normalizing Functor (universal normalization)
Usage
from civic_exchange_protocol.core_linker import ( generate_snfei, normalize_legal_name, apply_localization, )
Simple SNFEI generation¶
snfei, inputs = generate_snfei( legal_name="Springfield USD #12", country_code="US", address="123 Main St", )
With jurisdiction-specific localization¶
from civic_exchange_protocol.core_linker import apply_localization localized = apply_localization("MTA", "US/NY")
-> "metropolitan transportation authority"¶
CanonicalInput
dataclass
¶
Normalized input for SNFEI hashing.
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |
to_hash_string ¶
to_hash_string() -> str
Generate the concatenated string for hashing.
Format
legal_name_normalized|address_normalized|country_code|registration_date
Empty/None fields are included as empty strings to maintain consistent field positions.
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
to_hash_string_v2 ¶
to_hash_string_v2() -> str
Alternative format that omits empty fields.
This produces shorter strings but requires all implementations to handle optional fields identically.
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
580 581 582 583 584 585 586 587 588 589 590 591 592 | |
LocalizationConfig
dataclass
¶
Configuration for a specific jurisdiction.
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
apply_to_name ¶
apply_to_name(name: str) -> str
Apply jurisdiction-specific transformations to a name.
Order of application: 1. Agency name expansions 2. Abbreviation expansions 3. Entity type standardization 4. Custom rules
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
LocalizationRegistry ¶
Registry for loading and caching localization configurations.
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
__init__ ¶
__init__(config_dir: Path | None = None)
Initialize the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
Path | None
|
Optional path to localization YAML files. If None, only built-in configs are available. |
None
|
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
269 270 271 272 273 274 275 276 277 | |
get_config ¶
get_config(jurisdiction: str) -> LocalizationConfig
Get localization config for a jurisdiction.
Falls back through parent jurisdictions if specific config not found. Merges child config with parent config for inheritance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jurisdiction
|
str
|
Jurisdiction code (e.g., "us/ca", "ca/on"). Case-insensitive - will be normalized to lowercase. |
required |
Returns:
| Type | Description |
|---|---|
LocalizationConfig
|
LocalizationConfig for the jurisdiction (merged with parent). |
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
merge_configs ¶
merge_configs(
child: LocalizationConfig, parent: LocalizationConfig
) -> LocalizationConfig
Merge child config with parent (child overrides parent).
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
LocalizationRule
dataclass
¶
A single localization transformation rule.
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
33 34 35 36 37 38 39 40 | |
Snfei
dataclass
¶
A validated SNFEI (64-character lowercase hex string).
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
__post_init__ ¶
__post_init__() -> None
Validate SNFEI format after initialization.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
32 33 34 35 36 37 | |
__repr__ ¶
__repr__() -> str
Return abbreviated representation of SNFEI.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
43 44 45 | |
__str__ ¶
__str__() -> str
Return string representation of SNFEI.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
39 40 41 | |
as_str ¶
as_str() -> str
Return the hash value (for API compatibility).
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
47 48 49 | |
short ¶
short(length: int = 12) -> str
Return a shortened version for display.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
51 52 53 | |
SnfeiResult
dataclass
¶
Result of SNFEI generation with confidence metadata.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
to_dict ¶
to_dict() -> dict
Convert result to dictionary for serialization.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
apply_localization ¶
apply_localization(name: str, jurisdiction: str) -> str
Apply localization transforms to a name.
This is the Localization Functor L.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Raw entity name. |
required |
jurisdiction
|
str
|
Jurisdiction code (e.g., "US/CA"). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Name with jurisdiction-specific transforms applied. |
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
build_canonical_input ¶
build_canonical_input(
legal_name: str,
country_code: str,
address: str | None = None,
registration_date: str | None = None,
) -> CanonicalInput
Build a canonical input structure from raw entity data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
legal_name
|
str
|
Raw legal name. |
required |
country_code
|
str
|
ISO 3166-1 alpha-2 country code. |
required |
address
|
str | None
|
Optional street address. |
None
|
registration_date
|
str | None
|
Optional registration/formation date. |
None
|
Returns:
| Type | Description |
|---|---|
CanonicalInput
|
CanonicalInput with all fields normalized. |
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
compute_snfei ¶
compute_snfei(canonical: CanonicalInput) -> Snfei
Compute SNFEI from canonical input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canonical
|
CanonicalInput
|
Normalized input structure. |
required |
Returns:
| Type | Description |
|---|---|
Snfei
|
Computed SNFEI. |
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
56 57 58 59 60 61 62 63 64 65 66 67 | |
generate_snfei ¶
generate_snfei(
legal_name: str,
country_code: str,
address: str | None = None,
registration_date: str | None = None,
) -> tuple[Snfei, CanonicalInput]
Generate an SNFEI from raw entity attributes.
This is the main entry point for SNFEI generation. It applies the Normalizing Functor to all inputs before hashing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
legal_name
|
str
|
Raw legal name from source system. |
required |
country_code
|
str
|
ISO 3166-1 alpha-2 country code (e.g., "US", "CA"). |
required |
address
|
str | None
|
Optional primary street address. |
None
|
registration_date
|
str | None
|
Optional formation/registration date. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Snfei, CanonicalInput]
|
Tuple of (SNFEI, CanonicalInput) for verification. |
Example
snfei, inputs = generate_snfei( ... legal_name="Springfield Unified Sch. Dist., Inc.", ... country_code="US", ... address="123 Main St., Suite 100", ... registration_date="01/15/1985", ... ) print(snfei) a1b2c3d4... print(inputs.legal_name_normalized) springfield unified school district incorporated
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
generate_snfei_simple ¶
generate_snfei_simple(
legal_name: str,
country_code: str,
address: str | None = None,
) -> str
Generate SNFEI as a simple hex string.
Convenience function that returns just the hash value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
legal_name
|
str
|
Raw legal name. |
required |
country_code
|
str
|
ISO 3166-1 alpha-2 country code. |
required |
address
|
str | None
|
Optional primary street address. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
64-character lowercase hex SNFEI string. |
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
generate_snfei_with_confidence ¶
generate_snfei_with_confidence(
legal_name: str,
country_code: str,
address: str | None = None,
registration_date: str | None = None,
lei: str | None = None,
sam_uei: str | None = None,
) -> SnfeiResult
Generate SNFEI with confidence scoring and tier classification.
Tier Classification: - Tier 1: Entity has LEI (global identifier) - confidence 1.0 - Tier 2: Entity has SAM UEI (federal identifier) - confidence 0.95 - Tier 3: Entity uses SNFEI (computed hash) - confidence varies
Tier 3 Confidence Scoring: - Base: 0.5 (name + country only) - +0.2 if address is provided - +0.2 if registration_date is provided - +0.1 if name is reasonably long (>3 words)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
legal_name
|
str
|
Raw legal name. |
required |
country_code
|
str
|
ISO 3166-1 alpha-2 country code. |
required |
address
|
str | None
|
Optional street address. |
None
|
registration_date
|
str | None
|
Optional registration date. |
None
|
lei
|
str | None
|
Optional LEI (Legal Entity Identifier). |
None
|
sam_uei
|
str | None
|
Optional SAM.gov Unique Entity Identifier. |
None
|
Returns:
| Type | Description |
|---|---|
SnfeiResult
|
SnfeiResult with SNFEI, confidence score, and metadata. |
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
get_localization_config ¶
get_localization_config(
jurisdiction: str,
) -> LocalizationConfig
Get localization config for a jurisdiction (convenience function).
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
436 437 438 | |
normalize_address ¶
normalize_address(
address: str, remove_secondary: bool = True
) -> str
Normalize a street address for SNFEI hashing.
Pipeline: 1. Lowercase 2. ASCII transliteration 3. Remove secondary unit designators (apt, suite, etc.) 4. Remove punctuation 5. Expand postal abbreviations 6. Collapse whitespace
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
Raw street address. |
required |
remove_secondary
|
bool
|
Whether to remove apartment/suite numbers. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Normalized address string. |
Example
normalize_address("123 N. Main St., Suite 400") "123 north main street"
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | |
normalize_legal_name ¶
normalize_legal_name(
name: str,
remove_stop_words: bool = True,
preserve_initial_stop: bool = False,
) -> str
Apply the universal normalization pipeline to a legal name.
Pipeline (in order): 1. Convert to lowercase 2. ASCII transliteration 3. Remove punctuation 4. Collapse whitespace 5. Expand abbreviations 6. Remove stop words (optional) 7. Final trim
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Raw legal name from source system. |
required |
remove_stop_words
|
bool
|
Whether to filter out stop words. |
True
|
preserve_initial_stop
|
bool
|
If True, preserve stop word at start of name. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Normalized name suitable for SNFEI hashing. |
Example
normalize_legal_name("The Springfield Unified Sch. Dist., Inc.") "springfield unified school district incorporated"
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
normalize_registration_date ¶
normalize_registration_date(date_str: str) -> str | None
Normalize a registration date to ISO 8601 format.
Returns None if date cannot be parsed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_str
|
str
|
Date string in various formats. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
ISO 8601 date string (YYYY-MM-DD) or None. |
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
generator ¶
SNFEI Hash Generation.
This module computes the final SNFEI (Sub-National Federated Entity Identifier) from normalized entity attributes.
The SNFEI formula
SNFEI = SHA256(Concatenate[ legal_name_normalized, address_normalized, country_code, registration_date ])
All inputs must pass through the Normalizing Functor before hashing.
Snfei
dataclass
¶
A validated SNFEI (64-character lowercase hex string).
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
__post_init__ ¶
__post_init__() -> None
Validate SNFEI format after initialization.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
32 33 34 35 36 37 | |
__repr__ ¶
__repr__() -> str
Return abbreviated representation of SNFEI.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
43 44 45 | |
__str__ ¶
__str__() -> str
Return string representation of SNFEI.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
39 40 41 | |
as_str ¶
as_str() -> str
Return the hash value (for API compatibility).
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
47 48 49 | |
short ¶
short(length: int = 12) -> str
Return a shortened version for display.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
51 52 53 | |
SnfeiResult
dataclass
¶
Result of SNFEI generation with confidence metadata.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
to_dict ¶
to_dict() -> dict
Convert result to dictionary for serialization.
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
compute_snfei ¶
compute_snfei(canonical: CanonicalInput) -> Snfei
Compute SNFEI from canonical input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canonical
|
CanonicalInput
|
Normalized input structure. |
required |
Returns:
| Type | Description |
|---|---|
Snfei
|
Computed SNFEI. |
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
56 57 58 59 60 61 62 63 64 65 66 67 | |
generate_snfei ¶
generate_snfei(
legal_name: str,
country_code: str,
address: str | None = None,
registration_date: str | None = None,
) -> tuple[Snfei, CanonicalInput]
Generate an SNFEI from raw entity attributes.
This is the main entry point for SNFEI generation. It applies the Normalizing Functor to all inputs before hashing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
legal_name
|
str
|
Raw legal name from source system. |
required |
country_code
|
str
|
ISO 3166-1 alpha-2 country code (e.g., "US", "CA"). |
required |
address
|
str | None
|
Optional primary street address. |
None
|
registration_date
|
str | None
|
Optional formation/registration date. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Snfei, CanonicalInput]
|
Tuple of (SNFEI, CanonicalInput) for verification. |
Example
snfei, inputs = generate_snfei( ... legal_name="Springfield Unified Sch. Dist., Inc.", ... country_code="US", ... address="123 Main St., Suite 100", ... registration_date="01/15/1985", ... ) print(snfei) a1b2c3d4... print(inputs.legal_name_normalized) springfield unified school district incorporated
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
generate_snfei_simple ¶
generate_snfei_simple(
legal_name: str,
country_code: str,
address: str | None = None,
) -> str
Generate SNFEI as a simple hex string.
Convenience function that returns just the hash value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
legal_name
|
str
|
Raw legal name. |
required |
country_code
|
str
|
ISO 3166-1 alpha-2 country code. |
required |
address
|
str | None
|
Optional primary street address. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
64-character lowercase hex SNFEI string. |
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
generate_snfei_with_confidence ¶
generate_snfei_with_confidence(
legal_name: str,
country_code: str,
address: str | None = None,
registration_date: str | None = None,
lei: str | None = None,
sam_uei: str | None = None,
) -> SnfeiResult
Generate SNFEI with confidence scoring and tier classification.
Tier Classification: - Tier 1: Entity has LEI (global identifier) - confidence 1.0 - Tier 2: Entity has SAM UEI (federal identifier) - confidence 0.95 - Tier 3: Entity uses SNFEI (computed hash) - confidence varies
Tier 3 Confidence Scoring: - Base: 0.5 (name + country only) - +0.2 if address is provided - +0.2 if registration_date is provided - +0.1 if name is reasonably long (>3 words)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
legal_name
|
str
|
Raw legal name. |
required |
country_code
|
str
|
ISO 3166-1 alpha-2 country code. |
required |
address
|
str | None
|
Optional street address. |
None
|
registration_date
|
str | None
|
Optional registration date. |
None
|
lei
|
str | None
|
Optional LEI (Legal Entity Identifier). |
None
|
sam_uei
|
str | None
|
Optional SAM.gov Unique Entity Identifier. |
None
|
Returns:
| Type | Description |
|---|---|
SnfeiResult
|
SnfeiResult with SNFEI, confidence score, and metadata. |
Source code in src/python/src/civic_exchange_protocol/snfei/generator.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
localization ¶
Localization Functor: Jurisdiction-Specific Transformations.
This module loads and applies jurisdiction-specific normalization rules BEFORE the universal Normalizing Functor is applied.
The Localization Functor L transforms raw local data into a canonical intermediate form that the universal normalizer can process:
L: RawLocal → IntermediateCanonical
N: IntermediateCanonical → FinalCanonical
SNFEI = Hash(N(L(raw_data)))
Directory Structure
/localization/ base.yaml # Default/fallback rules us/ base.yaml # US-wide rules ca.yaml # California-specific ny.yaml # New York-specific ca/ base.yaml # Canada-wide rules on.yaml # Ontario-specific qc.yaml # Quebec-specific
LocalizationConfig
dataclass
¶
Configuration for a specific jurisdiction.
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
apply_to_name ¶
apply_to_name(name: str) -> str
Apply jurisdiction-specific transformations to a name.
Order of application: 1. Agency name expansions 2. Abbreviation expansions 3. Entity type standardization 4. Custom rules
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
LocalizationRegistry ¶
Registry for loading and caching localization configurations.
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
__init__ ¶
__init__(config_dir: Path | None = None)
Initialize the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
Path | None
|
Optional path to localization YAML files. If None, only built-in configs are available. |
None
|
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
269 270 271 272 273 274 275 276 277 | |
get_config ¶
get_config(jurisdiction: str) -> LocalizationConfig
Get localization config for a jurisdiction.
Falls back through parent jurisdictions if specific config not found. Merges child config with parent config for inheritance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jurisdiction
|
str
|
Jurisdiction code (e.g., "us/ca", "ca/on"). Case-insensitive - will be normalized to lowercase. |
required |
Returns:
| Type | Description |
|---|---|
LocalizationConfig
|
LocalizationConfig for the jurisdiction (merged with parent). |
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
merge_configs ¶
merge_configs(
child: LocalizationConfig, parent: LocalizationConfig
) -> LocalizationConfig
Merge child config with parent (child overrides parent).
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
LocalizationRule
dataclass
¶
A single localization transformation rule.
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
33 34 35 36 37 38 39 40 | |
apply_localization ¶
apply_localization(name: str, jurisdiction: str) -> str
Apply localization transforms to a name.
This is the Localization Functor L.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Raw entity name. |
required |
jurisdiction
|
str
|
Jurisdiction code (e.g., "US/CA"). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Name with jurisdiction-specific transforms applied. |
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
get_localization_config ¶
get_localization_config(
jurisdiction: str,
) -> LocalizationConfig
Get localization config for a jurisdiction (convenience function).
Source code in src/python/src/civic_exchange_protocol/snfei/localization.py
436 437 438 | |
normalizer ¶
CEP Core Linker: The Normalizing Functor.
This module implements the universal normalization pipeline that transforms entity attributes into hash-ready canonical form for SNFEI generation.
The architecture follows the Category Theory foundation: - Localization Functor: Jurisdiction-specific transforms (YAML-driven) - Normalizing Functor: Universal normalization steps (this module) - SNFEI Hash: Final SHA-256 computation
Directory Structure
/core-linker/ normalizer.py # Universal normalization (this file) snfei.py # SNFEI hash generation address.py # Address normalization /localization/ US/ # US state-specific rules CA.yaml NY.yaml CA/ # Canada province-specific rules ON.yaml QC.yaml base.yaml # Fallback rules
Mathematical Foundation
The Normalizing Functor N transforms the category of Raw Entity Data into the category of Canonical Entity Data:
N: RawEntity → CanonicalEntity
Where N preserves identity (same entity always maps to same canonical form) and composition (N(L(x)) = N ∘ L(x) where L is the localization functor).
CanonicalInput
dataclass
¶
Normalized input for SNFEI hashing.
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |
to_hash_string ¶
to_hash_string() -> str
Generate the concatenated string for hashing.
Format
legal_name_normalized|address_normalized|country_code|registration_date
Empty/None fields are included as empty strings to maintain consistent field positions.
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
to_hash_string_v2 ¶
to_hash_string_v2() -> str
Alternative format that omits empty fields.
This produces shorter strings but requires all implementations to handle optional fields identically.
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
580 581 582 583 584 585 586 587 588 589 590 591 592 | |
build_canonical_input ¶
build_canonical_input(
legal_name: str,
country_code: str,
address: str | None = None,
registration_date: str | None = None,
) -> CanonicalInput
Build a canonical input structure from raw entity data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
legal_name
|
str
|
Raw legal name. |
required |
country_code
|
str
|
ISO 3166-1 alpha-2 country code. |
required |
address
|
str | None
|
Optional street address. |
None
|
registration_date
|
str | None
|
Optional registration/formation date. |
None
|
Returns:
| Type | Description |
|---|---|
CanonicalInput
|
CanonicalInput with all fields normalized. |
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
normalize_address ¶
normalize_address(
address: str, remove_secondary: bool = True
) -> str
Normalize a street address for SNFEI hashing.
Pipeline: 1. Lowercase 2. ASCII transliteration 3. Remove secondary unit designators (apt, suite, etc.) 4. Remove punctuation 5. Expand postal abbreviations 6. Collapse whitespace
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
Raw street address. |
required |
remove_secondary
|
bool
|
Whether to remove apartment/suite numbers. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Normalized address string. |
Example
normalize_address("123 N. Main St., Suite 400") "123 north main street"
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | |
normalize_legal_name ¶
normalize_legal_name(
name: str,
remove_stop_words: bool = True,
preserve_initial_stop: bool = False,
) -> str
Apply the universal normalization pipeline to a legal name.
Pipeline (in order): 1. Convert to lowercase 2. ASCII transliteration 3. Remove punctuation 4. Collapse whitespace 5. Expand abbreviations 6. Remove stop words (optional) 7. Final trim
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Raw legal name from source system. |
required |
remove_stop_words
|
bool
|
Whether to filter out stop words. |
True
|
preserve_initial_stop
|
bool
|
If True, preserve stop word at start of name. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Normalized name suitable for SNFEI hashing. |
Example
normalize_legal_name("The Springfield Unified Sch. Dist., Inc.") "springfield unified school district incorporated"
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
normalize_registration_date ¶
normalize_registration_date(date_str: str) -> str | None
Normalize a registration date to ISO 8601 format.
Returns None if date cannot be parsed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_str
|
str
|
Date string in various formats. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
ISO 8601 date string (YYYY-MM-DD) or None. |
Source code in src/python/src/civic_exchange_protocol/snfei/normalizer.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |