Skip to content

Commit 6d9ff57

Browse files
committed
docs: updates docs to reflect #77
1 parent b105d4f commit 6d9ff57

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

docs/docs/python-sdk.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ Personal Data Definitions are fields associated to a cardholder and are defined
367367
- children of the `personalDataFields` key in the cardholder detail
368368
- accessible via key name prefixed with the `@` symbol i.e the personal data field `Email` is accessible via the key `@Email`
369369

370+
370371
!!! tip
371372

372373
Note that the `personDataFields` has a `list` of objects, and each object has a single key which is the nae of the personal data field and the value is the related data.
@@ -399,10 +400,33 @@ and we had used the API client to fetch the cardholder detail (partial example):
399400
cardholder = await Cardholder.retrieve(340)
400401
```
401402

402-
you could access the `Email` field either via iterating over `cardholder.personal_data_definitions` and looking to match the `key` attribute of the object to `@Email` or using the parsed shortcut `cardholder.pdf.email`.
403+
`cardholder` would have two fields:
404+
- `personal_data_definitions` which is a list of `CardholderPersonalDataDefinition` objects
405+
- `pdf` which is a parsed object of the personal data fields
406+
407+
`cardholder.personal_data_definitions` is iterable, each instance exposing a `name` and `contents` fields. Use the `value` attribute of `contents` to access the PDF value:
403408

404-
The above is achieved by dynamically populating a placeholder object with dynamically generated keys. These are parsed and populate _once_ when the object has successfully parsed the `JSON` payload.
409+
```python
410+
for pdf in cardholder.personal_data_definitions:
411+
if pdf.name == '@Email':
412+
print(pdf.name, pdf.contents.value)
413+
```
405414

406415
!!! tip
407416

408417
See pyndatic's [Model validator](https://docs.pydantic.dev/latest/concepts/validators/#model-validators) feature in v2, in particular the `@model_validator(mode='after')` constructor.
418+
419+
The `cardholder` object will also expose a special attribute called `pdf`. Each instance available in the `personal_data_definitions` field will be mapped to a Pythonic `snake_cased` key, that lets you access the same `CardholderPersonalDataDefinition` object via the `@` prefixed key name. So the above example of accessing the `@Email` field can be done as follows:
420+
421+
```python
422+
cardholder.pdf.email.value
423+
```
424+
425+
The `pdf` attribute is dynamically populated object with dynamically generated keys. Here are some examples of how `PDF` field names are mapped to `snake_case` keys:
426+
427+
- `@Cardholder UID` would become `pdf.cardholder_uid`
428+
- `@City` would become `pdf.city`
429+
- `@Company Name` would become `pdf.company_name`
430+
- `@PINNumber` would become `pdf.pin_number`
431+
432+
Both approaches have their merits and you should use the one that suits your use case.

0 commit comments

Comments
 (0)