### Run Example Validation Script Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Execute the example demonstration script for the validation system. ```bash python example_validation.py ``` -------------------------------- ### Install pyiso20022 and xsdata Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Install the pyiso20022 package along with xsdata for XML parsing capabilities. This is a prerequisite for using the message generation and parsing features. ```bash pip install pyiso20022 pip install xsdata[cli,lxml,soap] ``` -------------------------------- ### Quick Start: Validate Field and Instance Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Demonstrates how to validate a single field using `validate_field` and a complete dataclass instance using `validate_instance`. Ensure necessary imports are included. ```python from pyiso20022.pacs.pacs_008_001_08.pacs_008_001_08 import PaymentIdentification7 from pyiso20022.tools.validation import validate_instance, validate_field # Validate a single field result = validate_field(PaymentIdentification7, 'uetr', 'invalid-uuid') if not result.is_valid: print(f"Validation failed: {result.errors[0].message}") # Validate a complete instance payment = PaymentIdentification7( end_to_end_id="E2E123", uetr="550e8400-e29b-41d4-a716-446655440000" ) result = validate_instance(payment) print(f"Valid: {result.is_valid}") ``` -------------------------------- ### Create ISO 20022 PACS.008 Message Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Demonstrates creating a PACS.008 MX payment message. Note that wrapper elements like <MSGRoot> may vary based on your setup. ```python from pyiso20022.pacs.pacs_008_001_08 import * import pyiso20022.head.head_001_001_02 as hd from xsdata.formats.dataclass.serializers import XmlSerializer from xsdata.formats.dataclass.serializers.config import SerializerConfig import uuid from lxml import etree from xsdata.models.datatype import XmlDateTime clr_sys = ClearingSystemIdentification3Choice(cd="STG") the_sttlinf = SettlementInstruction7(sttlm_mtd=SettlementMethod1Code("CLRG"), clr_sys=clr_sys) ``` -------------------------------- ### Example: UETR Validation Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Validates a UETR field against the expected UUID v4 format using `validate_field`. This example assumes the `PaymentIdentification7` dataclass and `validate_field` function are imported. ```python from pyiso20022.pacs.pacs_008_001_08.pacs_008_001_08 import PaymentIdentification7 from pyiso20022.tools.validation import validate_field # Valid UETR (UUID v4 format) result = validate_field( PaymentIdentification7, 'uetr', '550e8400-e29b-41d4-a716-446655440000' ) print(f"Valid: {result.is_valid}") # True ``` -------------------------------- ### Get Field Constraints Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Retrieves validation constraints for a specific model class. This is useful for understanding the rules applied to each field. ```python from pyiso20022.pacs.pacs_008_001_08.pacs_008_001_08 import PaymentIdentification7 from pyiso20022.tools.validation import get_constraints constraints = get_constraints(PaymentIdentification7) # You can then inspect the constraints dictionary for details like min_length, max_length, pattern, etc. ``` -------------------------------- ### Configure and Create XML Serializer Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Sets up an XmlSerializer with pretty printing enabled and no XML declaration. ```python config_subs = SerializerConfig(pretty_print=True, xml_declaration=False) serializer_subs = XmlSerializer(config=config_subs) ``` -------------------------------- ### Render XML for Header and Document Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Serializes the header and document objects into XML strings using their respective namespace maps. ```python header_el: str = serializer_subs.render(header, ns_map=ns_map_header) doc_el: str = serializer_subs.render(doc, ns_map=ns_map_doc) ``` -------------------------------- ### Create Charges Information Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Generates Charges7 object with amount and agent details. ```python chrgs_inf = Charges7(amt=zero_amt, agt=agt) ``` -------------------------------- ### Define Instruction for Next Agent Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Creates an InstructionForNextAgent1 object with specific instructions. ```python instr_for_nxt_agt = InstructionForNextAgent1(instr_inf="HOLD") ``` -------------------------------- ### Define Currency and Amount Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Creates an ActiveOrHistoricCurrencyAndAmount object for a zero value in GBP. ```python zero_amt = ActiveOrHistoricCurrencyAndAmount(ccy="GBP", value=0) ``` -------------------------------- ### Combine Header and Document XML Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Creates a root XML element and appends the serialized header and document elements. ```python msg_root = etree.Element('MSGRoot') msg_root.append(etree.fromstring(header_el)) msg_root.append(etree.fromstring(doc_el)) ``` -------------------------------- ### Define Party Information Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Constructs PartyIdentification135 objects for ultimate debtor, initiating party, and registered debtor. ```python ult_debtr = PartyIdentification135(nm="Mr Ulti Debtor", pstl_adr=ult_pstl) initg_pty = PartyIdentification135(nm="Ms Initd Party", pstl_adr=ult_pstl) reg_debtr = PartyIdentification135(nm="Mrs Reg Debtor", pstl_adr=dbtr_pstl) ``` -------------------------------- ### Create Document with Message Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Wraps the FitoFicustomerCreditTransferV08 message within a Document object. ```python doc = Document(fito_ficstmr_cdt_trf=f2f_cust_cred_trans) ``` -------------------------------- ### Create a GroupHeader93 Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Constructs a GroupHeader93 object with message ID, transaction count, creation date, and settlement information. ```python grp_header = GroupHeader93(msg_id="MIDTheMessageId", nb_of_txs=1, cre_dt_tm=XmlDateTime.from_string("2019-01-01T00:00:00"), sttlm_inf=the_sttlinf) ``` -------------------------------- ### Create ISO 20022 PAIN.001 Message Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Generates a PAIN.001.001.08 payment initiation message and writes it to an XML file. Ensure all necessary imports are present. ```python from pyiso20022.pain.pain_001_001_08 import * from xsdata.formats.dataclass.serializers import XmlSerializer from xsdata.formats.dataclass.serializers.config import SerializerConfig from xsdata.models.datatype import XmlDate initg_pty__id = Party11Choice( org_id=OrganisationIdentification8( othr=GenericOrganisationIdentification1( id="uktestdda") )) initg_pty = PartyIdentification43(nm="TXB Test Account", id=initg_pty__id) grp_hdr = GroupHeader48(msg_id="test-160620", cre_dt_tm="2019-12-03T13:01:00+00:00", nb_of_txs=1, ctrl_sum=10, initg_pty=initg_pty) dbtr__pstl_adr = PostalAddress6(strt_nm="DBTR LUEZOF", bldg_nb="88", pst_cd="052", twn_nm="VVR MBDB", ctry="QA") dbtr = PartyIdentification43(nm="UFXQHBE", pstl_adr=dbtr__pstl_adr) dbtr_acct = CashAccount24(id=AccountIdentification4Choice( othr=GenericAccountIdentification1(id="50000970")), ccy="GBP") dbtr_agt = BranchAndFinancialInstitutionIdentification5( fin_instn_id=FinancialInstitutionIdentification8( bicfi="GSLDGB20")) amt = AmountType4Choice(instd_amt=ActiveOrHistoricCurrencyAndAmount(value=10, ccy="GBP")) cdtr_agt = BranchAndFinancialInstitutionIdentification5( fin_instn_id=FinancialInstitutionIdentification8( bicfi="BARCGB22")) cdtr__pstl_adr = PostalAddress6(strt_nm="CDTR LUEZOF", bldg_nb="99", pst_cd="052", twn_nm="VVR MBDB", ctry="QA") cdtr = PartyIdentification43(nm="Creditor account name", pstl_adr=cdtr__pstl_adr) cdtr_acct = CashAccount24(id=AccountIdentification4Choice( othr=GenericAccountIdentification1(id="12345678"))) rmt_inf = RemittanceInformation11(ustrd="USD Payment from USD account") cdt_trf_tx_inf = CreditTransferTransaction26( pmt_id=PaymentIdentification1(end_to_end_id="test-160620"), pmt_tp_inf=PaymentTypeInformation19( ctgy_purp=CategoryPurpose1Choice(prtry="Tax Payment")), amt=amt, cdtr_agt=cdtr_agt, cdtr=cdtr, cdtr_acct=cdtr_acct, purp=Purpose2Choice(prtry="Purpose of payment") , rmt_inf=rmt_inf) pmt_inf = PaymentInstruction22(pmt_inf_id="test-160620", pmt_mtd=PaymentMethod3Code("TRF"), reqd_exctn_dt=DateAndDateTimeChoice( dt=XmlDate.from_string("2020-06-16")), dbtr=dbtr, dbtr_acct=dbtr_acct, dbtr_agt=dbtr_agt, cdt_trf_tx_inf=cdt_trf_tx_inf) cstmr_cdt_trf_initn = CustomerCreditTransferInitiationV08(grp_hdr=grp_hdr, pmt_inf=pmt_inf) doc = Document(cstmr_cdt_trf_initn=cstmr_cdt_trf_initn) ns_map_doc: dict[None, str] = { None: "urn:iso:std:iso:20022:tech:xsd:pain.001.001.08" } config = SerializerConfig(pretty_print=True, xml_declaration=True, encoding='UTF-8' ) serializer = XmlSerializer(config=config) xml_content = serializer.render(doc, ns_map=ns_map_doc) with open("my_pain_001_001_08_from_code.xml", "w") as xml_file: xml_file.write(xml_content) ``` -------------------------------- ### Create Application Header Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Constructs an AppHdr object for the message, including sender, receiver, message IDs, and creation timestamp. ```python fr_fiid = hd.FinancialInstitutionIdentification18(bicfi="BARCGB22") fr_bafii = hd.BranchAndFinancialInstitutionIdentification6(fin_instn_id=fr_fiid) fr_party44 = hd.Party44Choice(fiid=fr_bafii) to_fiid = hd.FinancialInstitutionIdentification18(bicfi="BARCGB22") to_bafii = hd.BranchAndFinancialInstitutionIdentification6(fin_instn_id=to_fiid) to_party44 = hd.Party44Choice(fiid=to_bafii) header = hd.AppHdr(fr=fr_party44, to=to_party44, biz_msg_idr="MIDRFGHJKL", msg_def_idr="pacs.008.001.08", biz_svc="boe.chaps.enh.01", cre_dt="2019-01-01T00:00:00", prty="NORM") ``` -------------------------------- ### Define Transaction Amounts Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Creates ActiveOrHistoricCurrencyAndAmount and ActiveCurrencyAndAmount objects for transaction values. ```python instd_amt = ActiveOrHistoricCurrencyAndAmount(ccy="GBP", value=555.01) intra_bk_st_amt = ActiveCurrencyAndAmount(ccy="GBP", value=555.01) ``` -------------------------------- ### Validate Instance with Multiple Errors Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Demonstrates validating an instance that has multiple fields failing validation. Use strict=False to collect all errors. ```python from pyiso20022.pacs.pacs_008_001_08.pacs_008_001_08 import PaymentIdentification7 from pyiso20022.tools.validation import validate_instance # Instance with multiple validation errors payment = PaymentIdentification7( end_to_end_id="", # Too short (min_length = 1) tx_id="a" * 50, # Too long (max_length = 35) uetr="invalid-uuid" # Invalid pattern ) # Non-strict validation (collect all errors) result = validate_instance(payment, strict=False) print(f"Valid: {result.is_valid}") # False print(f"Number of errors: {len(result.errors)}") # 3 for error in result.errors: print(f"- {error}") ``` -------------------------------- ### Write XML to File Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Saves the generated full XML message to a file named 'my_pacs_008_from_code.xml'. ```python with open("my_pacs_008_from_code.xml", "w") as xml_file: xml_file.write(str(msg_full, encoding='utf-8')) ``` -------------------------------- ### Create a PaymentIdentification7 Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Defines payment identification details including instruction ID, end-to-end ID, transaction ID, and a unique end-to-end reference. ```python pmt_id = PaymentIdentification7(instr_id="IXWEDRFTGHJK5", end_to_end_id="E2EDRFGHJK7", tx_id="TIDRFGHJ54678", uetr=str(uuid.uuid4())) ``` -------------------------------- ### Check UETR and End-to-End ID Constraints Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md This snippet demonstrates how to access and print UETR pattern and end-to-end ID constraints (required, min length, max length) from a constraints dictionary. ```python uetr_constraints = constraints['uetr'] print(f"UETR pattern: {uetr_constraints['pattern']}") # Check end_to_end_id constraints e2e_constraints = constraints['end_to_end_id'] print(f"Required: {e2e_constraints['required']}") print(f"Min length: {e2e_constraints['min_length']}") print(f"Max length: {e2e_constraints['max_length']}") ``` -------------------------------- ### Create and Validate a PACS.008 Message Source: https://github.com/phoughton/pyiso20022/blob/main/README.md This snippet demonstrates how to construct a PACS.008 message programmatically, serialize it to XML, and then validate it using the pyiso20022 library. It also shows how to print validation results. ```python from pyiso20022.utils import XmlSerializer, SerializerConfig from pyiso20022.utils.validation import validate_message from lxml import etree from pyiso20022.head import hd from pyiso20022.pacs import pacs008 # Assuming 'doc' is a pre-defined pacs.008 message object # For demonstration, let's create a placeholder doc object doc = pacs008.Document() # Create the AppHdr fr_fiid = hd.FinancialInstitutionIdentification18(bicfi="BARCGB22") fr_bafii = hd.BranchAndFinancialInstitutionIdentification6(fin_instn_id=fr_fiid) fr_party44 = hd.Party44Choice(fiid=fr_bafii) to_fiid = hd.FinancialInstitutionIdentification18(bicfi="BARCGB22") to_bafii = hd.BranchAndFinancialInstitutionIdentification6(fin_instn_id=to_fiid) to_party44 = hd.Party44Choice(fiid=to_bafii) header = hd.AppHdr(fr=fr_party44, to=to_party44, biz_msg_idr="MIDRFGHJKL", msg_def_idr="pacs.008.001.08", biz_svc="boe.chaps.enh.01", cre_dt="2019-01-01T00:00:00", prty="NORM") config_subs = SerializerConfig(pretty_print=True, xml_declaration=False) serializer_subs = XmlSerializer(config=config_subs) ns_map_header: dict[None, str] = { None: "urn:iso:std:iso:20022:tech:xsd:head.001.001.02" } ns_map_doc: dict[None, str] = { None: "urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08" } header_el: str = serializer_subs.render(header, ns_map=ns_map_header) doc_el: str = serializer_subs.render(doc, ns_map=ns_map_doc) msg_root = etree.Element('RequestPayload') msg_root.append(etree.fromstring(header_el)) msg_root.append(etree.fromstring(doc_el)) msg_full = etree.tostring(msg_root, pretty_print=True, xml_declaration=True, encoding='UTF-8') with open("my_pacs_008_from_code.xml", "w") as xml_file: xml_file.write(str(msg_full, encoding='utf-8')) # Assuming f2f_cust_cred_trans is a pre-defined message object for validation # For demonstration, let's use a placeholder f2f_cust_cred_trans = pacs008.Document() result = validate_message(f2f_cust_cred_trans, strict=False) print(result.to_summary_yaml()) print() print("## Detailed Error Report") print(result.to_yaml()) ``` -------------------------------- ### Create Credit Transfer Transaction Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Constructs a CreditTransferTransaction39 object with all relevant payment details. ```python cdtrtx = CreditTransferTransaction39(pmt_id=pmt_id, chrg_br=ChargeBearerType1Code("SHAR"), intr_bk_sttlm_dt="2019-01-01", intr_bk_sttlm_amt=intra_bk_st_amt, instd_amt=instd_amt, chrgs_inf=[chrgs_inf], instg_agt=instg_agt, instd_agt=instd_agt, ultmt_dbtr=ult_debtr, initg_pty=initg_pty, dbtr=reg_debtr, dbtr_agt=instg_agt, cdtr_agt=instd_agt, instr_for_nxt_agt=[instr_for_nxt_agt], purp=purp, rltd_rmt_inf=[rem_loc], rmt_inf=rmt_inf) ``` -------------------------------- ### Convert CAMT.053 to Excel Source: https://github.com/phoughton/pyiso20022/blob/main/README.md This snippet shows how to use the `camt053_to_excel` utility to convert a CAMT.053 XML file into an Excel file. It extracts transaction entries and translates element names for better readability in Excel. ```python import pyiso20022.tools as isotools isotools.camt053_to_excel("my_camt053_file.xml", "my_camt053_excel_file.xlsx") ``` -------------------------------- ### Run Pytest Validation Tests Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Execute the validation system's tests using pytest. This command runs all tests verbosely. ```bash python -m pytest tests/test_validation.py -v ``` -------------------------------- ### Define Namespace Maps Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Specifies namespace mappings for the Application Header and the Document. ```python ns_map_header: dict[None, str] = { None: "urn:iso:std:iso:20022:tech:xsd:head.001.001.02" } ns_map_doc: dict[None, str] = { None: "urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08" } ``` -------------------------------- ### validate_instance(instance, strict=True) Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Validates a complete dataclass instance against all its field constraints. It can either stop on the first error or collect all errors based on the strict parameter. ```APIDOC ## validate_instance(instance, strict=True) ### Description Validates a complete dataclass instance against all its field constraints. ### Parameters #### Parameters - **instance** (object) - Required - The dataclass instance to validate - **strict** (boolean) - Optional - If True, stops on first error. If False, collects all errors. Defaults to True. ### Returns - **ValidationResult** - An object containing the validation results, including validity status and a list of errors. ``` -------------------------------- ### Define Purpose and Remittance Information Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Creates Purpose2Choice and RemittanceInformation16 objects. ```python purp = Purpose2Choice(cd="PHON") rem_loc = RemittanceLocation7(rmt_id="BUSINESS DEBIT") rmt_inf = RemittanceInformation16(ustrd=["INVOICE 123456"]) ``` -------------------------------- ### Define Branch and Financial Institution Identifications Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Constructs BranchAndFinancialInstitutionIdentification6 objects using financial institution IDs. ```python agt = BranchAndFinancialInstitutionIdentification6(fin_instn_id=bic_1) instd_agt = BranchAndFinancialInstitutionIdentification6(fin_instn_id=bic_2) instg_agt = BranchAndFinancialInstitutionIdentification6(fin_instn_id=bic_1) ``` -------------------------------- ### Create FitoFicustomerCreditTransferV08 Message Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Assembles the FitoFicustomerCreditTransferV08 message with group header and credit transfer transactions. ```python f2f_cust_cred_trans = FitoFicustomerCreditTransferV08(grp_hdr=grp_header, cdt_trf_tx_inf=[cdtrtx]) ``` -------------------------------- ### Define Postal Addresses Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Creates PostalAddress24 objects for ultimate and debtor postal addresses. ```python ult_pstl = PostalAddress24(bldg_nm="10", strt_nm="Cheapside", twn_nm="London", ctry="GB") dbtr_pstl = PostalAddress24(bldg_nm="11", strt_nm="Farside", twn_nm="York", ctry="GB") ``` -------------------------------- ### Generate Full XML Message Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Converts the combined XML structure into a byte string with pretty printing and XML declaration. ```python msg_full = etree.tostring(msg_root, pretty_print=True, xml_declaration=True, encoding='UTF-8') ``` -------------------------------- ### Validate Currency Amount Instance Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Validates an ActiveCurrencyAndAmount instance. This is useful for ensuring that monetary values and their currencies are correctly formatted. ```python from decimal import Decimal from pyiso20022.pacs.pacs_008_001_08.pacs_008_001_08 import ActiveCurrencyAndAmount from pyiso20022.tools.validation import validate_instance # Valid amount amount = ActiveCurrencyAndAmount( value=Decimal('100.50'), ccy='USD' ) result = validate_instance(amount) print(f"Valid: {result.is_valid") # True # Invalid amount (negative value) amount = ActiveCurrencyAndAmount( value=Decimal('-10.00'), ccy='USD' ) result = validate_instance(amount) print(f"Valid: {result.is_valid") # False ``` -------------------------------- ### Create and Validate PACS.008 Message Source: https://github.com/phoughton/pyiso20022/blob/main/README.md This snippet demonstrates the creation of a PACS.008 message, including all necessary components like Group Header, Settlement Information, Payment Identification, and Credit Transfer Transaction details. It then serializes the message to XML and validates it using the `validate_message` function. This is useful for understanding the structure and content of a PACS.008 message. ```python from pyiso20022.pacs.pacs_008_001_08 import * import pyiso20022.head.head_001_001_02 as hd from xsdata.formats.dataclass.serializers import XmlSerializer from xsdata.formats.dataclass.serializers.config import SerializerConfig import uuid from lxml import etree from xsdata.models.datatype import XmlDateTime from pyiso20022.tools.validation import validate_message from decimal import Decimal clr_sys = ClearingSystemIdentification3Choice(cd="STG") the_sttlinf = SettlementInstruction7(sttlm_mtd=SettlementMethod1Code("CLRG"), clr_sys=clr_sys) # Create the Group Header grp_header = GroupHeader93(msg_id="MIDTheMessageId", nb_of_txs=1, cre_dt_tm=XmlDateTime.from_string("2019-01-01T00:00:00"), sttlm_inf=the_sttlinf) pmt_id = PaymentIdentification7(instr_id="IXWEDRFTGHJK5", end_to_end_id="E2EDRFGHJK7", tx_id="TIDRFGHJ54678aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", uetr="not-a-valid-uuid") zero_amt = ActiveOrHistoricCurrencyAndAmount(ccy="GBP", value=0) bic_1 = FinancialInstitutionIdentification18("BARCGB22") bic_2 = FinancialInstitutionIdentification18("VODAGB23") agt = BranchAndFinancialInstitutionIdentification6(fin_instn_id=bic_1) instd_agt = BranchAndFinancialInstitutionIdentification6(fin_instn_id=bic_2) instg_agt = BranchAndFinancialInstitutionIdentification6(fin_instn_id=bic_1) chrgs_inf = Charges7(amt=zero_amt, agt=agt) ult_pstl = PostalAddress24(bldg_nm="10", strt_nm="Cheapside", twn_nm="London", ctry="GB") dbtr_pstl = PostalAddress24(bldg_nm="11", strt_nm="Farside", twn_nm="York", ctry="GB") ult_debtr = PartyIdentification135(nm="Mr Ulti Debtor", pstl_adr=ult_pstl) initg_pty = PartyIdentification135(nm="Ms Initd Party", pstl_adr=ult_pstl) reg_debtr = PartyIdentification135(nm="Mrs Reg Debtor", pstl_adr=dbtr_pstl) instr_for_nxt_agt = InstructionForNextAgent1(instr_inf="HOLD") instd_amt = ActiveOrHistoricCurrencyAndAmount(ccy="GBP", value=Decimal('-555.01')) intra_bk_st_amt = ActiveCurrencyAndAmount(ccy="GBP", value=Decimal('555.01')) purp = Purpose2Choice(cd="PHON") rem_loc = RemittanceLocation7(rmt_id="BUSINESS DEBIT") rmt_inf = RemittanceInformation16(ustrd=["INVOICE 123456"]) cdtr = PartyIdentification135(nm="Global Suppliers Inc") cdtrtx = CreditTransferTransaction39(pmt_id=pmt_id, chrg_br=ChargeBearerType1Code("SHAR"), intr_bk_sttlm_dt="2019-01-01", intr_bk_sttlm_amt=intra_bk_st_amt, instd_amt=instd_amt, chrgs_inf=[chrgs_inf], instg_agt=instg_agt, instd_agt=instd_agt, ultmt_dbtr=ult_debtr, initg_pty=initg_pty, dbtr=reg_debtr, dbtr_agt=instg_agt, cdtr=cdtr, cdtr_agt=instd_agt, instr_for_nxt_agt=[instr_for_nxt_agt], purp=purp, rltd_rmt_inf=[rem_loc], rmt_inf=rmt_inf) f2f_cust_cred_trans = FitoFicustomerCreditTransferV08(grp_hdr=grp_header, cdt_trf_tx_inf=[cdtrtx]) doc = Document(fito_ficstmr_cdt_trf=f2f_cust_cred_trans) ``` -------------------------------- ### Define Financial Institution Identifications Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Creates FinancialInstitutionIdentification18 objects for specific BIC codes. ```python bic_1 = FinancialInstitutionIdentification18("BARCGB22") bic_2 = FinancialInstitutionIdentification18("VODAGB23") ``` -------------------------------- ### Parse an ISO 20022 PAIN.001 Message Source: https://github.com/phoughton/pyiso20022/blob/main/README.md Use XmlParser from xsdata to parse a PAIN.001 message from an XML file. This snippet demonstrates how to load the document and access specific fields like the debtor's postal code. ```python from xsdata.formats.dataclass.parsers import XmlParser from pyiso20022.pain.pain_001_001_08 import * import sys parser = XmlParser() # Read in a file, you can get an example PAIN (Payment Initiation) message from: # https://developer.gs.com/docs/services/transaction-banking/pain001sample/ with open("example_files/gs_pain/pain001_001_08.xml", "rb") as xml_file: doc: Document = parser.parse(xml_file, Document, ) # Print out the Post Code. print(doc.cstmr_cdt_trf_initn.pmt_inf[0].dbtr.pstl_adr.pst_cd) ``` -------------------------------- ### validate_message(instance, strict=True) Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Validates an entire ISO20022 message recursively, ensuring all nested structures and list constraints are met. Similar to `validate_instance` but specifically designed for top-level message objects. ```APIDOC ## validate_message(instance, strict=True) ### Description Validates a complete ISO20022 message recursively, including all nested structures and lists. ### Parameters #### Parameters - **instance** (object) - Required - The message instance to validate (typically Document or root message) - **strict** (boolean) - Optional - If True, stops on first error. If False, collects all errors. Defaults to True. ### Returns - **ValidationResult** - A ValidationResult object with nested field paths for errors. ``` -------------------------------- ### get_constraints(dataclass_type) Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Extracts all defined validation constraints for the fields within a given dataclass type. This function is useful for introspection and understanding the validation rules applied to a specific data structure. ```APIDOC ## get_constraints(dataclass_type) ### Description Extracts all validation constraints for fields in a dataclass. ### Parameters #### Parameters - **dataclass_type** (type) - Required - The dataclass type to analyze ### Returns - **dict** - A dictionary mapping field names to their respective constraints. ``` -------------------------------- ### Validate UETR Field Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Validates a UETR field against its expected pattern. Use this to check the format of unique transaction reference numbers. ```python from pyiso20022.pacs.pacs_008_001_08.pacs_008_001_08 import PaymentIdentification7 from pyiso20022.tools.validation import validate_field result = validate_field( PaymentIdentification7, 'uetr', 'not-a-valid-uuid' ) print(f"Valid: {result.is_valid}") # False print(f"Error: {result.errors[0].message}") ``` -------------------------------- ### validate_field(dataclass_type, field_name, value) Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Validates a single field value against its defined constraints within a specified dataclass type. This is useful for targeted validation of individual data points. ```APIDOC ## validate_field(dataclass_type, field_name, value) ### Description Validates a single field value against its constraints. ### Parameters #### Parameters - **dataclass_type** (type) - Required - The dataclass type containing the field - **field_name** (string) - Required - Name of the field to validate - **value** (any) - Required - Value to validate ### Returns - **ValidationResult** - An object containing the validation results for the single field. ``` -------------------------------- ### Validate Complete PACS.008 Message Source: https://github.com/phoughton/pyiso20022/blob/main/VALIDATION_README.md Validates a full PACS.008 message structure. This is used for end-to-end message integrity checks. ```python from decimal import Decimal from datetime import datetime from xsdata.models.datatype import XmlDateTime from pyiso20022.pacs.pacs_008_001_08.pacs_008_001_08 import ( Document, FitoFicustomerCreditTransferV08, GroupHeader93, CreditTransferTransaction39, PaymentIdentification7, ActiveCurrencyAndAmount, BranchAndFinancialInstitutionIdentification6, FinancialInstitutionIdentification18, PartyIdentification135, SettlementInstruction7, SettlementMethod1Code, ChargeBearerType1Code ) from pyiso20022.tools.validation import validate_message # Create a complete PACS.008 message settlement_instruction = SettlementInstruction7( sttlm_mtd=SettlementMethod1Code.CLRG ) group_header = GroupHeader93( msg_id="MSG20250111001", cre_dt_tm=XmlDateTime.from_datetime(datetime.now()), nb_of_txs="1", sttlm_inf=settlement_instruction ) # Create financial institutions debtor_agent = BranchAndFinancialInstitutionIdentification6( fin_instn_id=FinancialInstitutionIdentification18(bicfi="DEUTDEFF") ) creditor_agent = BranchAndFinancialInstitutionIdentification6( fin_instn_id=FinancialInstitutionIdentification18(bicfi="CHASUS33") ) # Create payment transaction payment_id = PaymentIdentification7( end_to_end_id="E2E20250111001", uetr="550e8400-e29b-41d4-a716-446655440000" ) settlement_amount = ActiveCurrencyAndAmount( value=Decimal('50000.00'), ccy='USD' ) credit_transfer = CreditTransferTransaction39( pmt_id=payment_id, intr_bk_sttlm_amt=settlement_amount, chrg_br=ChargeBearerType1Code.SHAR, dbtr=PartyIdentification135(nm="ACME Corporation Ltd"), dbtr_agt=debtor_agent, cdtr=PartyIdentification135(nm="Global Suppliers Inc"), cdtr_agt=creditor_agent ) # Create the complete message fi_to_fi_transfer = FitoFicustomerCreditTransferV08( grp_hdr=group_header, cdt_trf_tx_inf=[credit_transfer] ) document = Document(fito_ficstmr_cdt_trf=fi_to_fi_transfer) # Validate the complete message result = validate_message(document) print(f"Valid: {result.is_valid}") # True # Example with validation errors invalid_payment_id = PaymentIdentification7( end_to_end_id="", # Invalid: empty string uetr="invalid-uuid" # Invalid: wrong pattern ) invalid_credit_transfer = CreditTransferTransaction39( pmt_id=invalid_payment_id, intr_bk_sttlm_amt=settlement_amount, chrg_br=ChargeBearerType1Code.SHAR, dbtr=PartyIdentification135(nm="ACME Corporation Ltd"), dbtr_agt=debtor_agent, cdtr=PartyIdentification135(nm="Global Suppliers Inc"), cdtr_agt=creditor_agent ) invalid_transfer = FitoFicustomerCreditTransferV08( grp_hdr=group_header, cdt_trf_tx_inf=[invalid_credit_transfer] ) invalid_document = Document(fito_ficstmr_cdt_trf=invalid_transfer) # Validate message with errors result = validate_message(invalid_document, strict=False) print(f"Valid: {result.is_valid}") # False for error in result.errors: print(f"Field: {error.field_name}") print(f"Error: {error.message}") # Field paths will show nested structure like: # fito_ficstmr_cdt_trf.cdt_trf_tx_inf.[0].pmt_id.end_to_end_id # fito_ficstmr_cdt_trf.cdt_trf_tx_inf.[0].pmt_id.uetr ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.