You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/python-sdk.md
+26-2Lines changed: 26 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -367,6 +367,7 @@ Personal Data Definitions are fields associated to a cardholder and are defined
367
367
- children of the `personalDataFields` key in the cardholder detail
368
368
- accessible via key name prefixed with the `@` symbol i.e the personal data field `Email` is accessible via the key `@Email`
369
369
370
+
370
371
!!! tip
371
372
372
373
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):
399
400
cardholder =await Cardholder.retrieve(340)
400
401
```
401
402
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:
403
408
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
+
```
405
414
406
415
!!! tip
407
416
408
417
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