{"templateId":"markdown","sharedDataIds":{},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"XRPL Python Code Sample Conventions","siteUrl":"https://xrpl.org/","llmstxt":{"hide":false,"title":"XRPL Developer Portal & Documentation","description":"Explore XRP Ledger documentation, blogs, and other blockchain developer resources needed to start building and integrating with the ledger.","details":{"content":"XRP Ledger concepts, use cases, tutorials, references, and other blockchain developer resources. Also, stay up to date with release announcements and more through the XRPL Blog."},"sections":[{"title":"Introduction","description":"A high-level introduction to the XRP Ledger.","includeFiles":["docs/introduction/**/*.*","about/faq.md"],"excludeFiles":["docs/introduction/index.md"]},{"title":"Use Cases","description":"Real-world applications and business scenarios for the XRP Ledger.","includeFiles":["docs/use-cases/**/*.*"],"excludeFiles":["docs/use-cases/index.md","docs/use-cases/defi/index.md"]},{"title":"Concepts","description":"Core concepts including accounts, tokens, transactions, consensus, and more.","includeFiles":["docs/concepts/**/*.*"],"excludeFiles":["docs/concepts/index.md","docs/concepts/decentralized-storage/index.md","docs/concepts/payment-types/index.md"]},{"title":"Tutorials","description":"Step-by-step guides for building on the XRP Ledger in JavaScript, Python, Go, and more.","includeFiles":["docs/tutorials/**/*.*"],"excludeFiles":[]},{"title":"References","description":"Protocol specification, transaction types, ledger entries, and API methods.","includeFiles":["docs/references/**/*.*"],"excludeFiles":["docs/references/xrp-api.md","docs/references/data-api.md","docs/references/protocol/index.md","docs/references/protocol/ledger-data/ledger-entry-types/index.md","docs/references/protocol/transactions/index.md","docs/references/protocol/transactions/types/index.md","docs/references/http-websocket-apis/api-conventions/index.md","docs/references/http-websocket-apis/public-api-methods/*/index.md","docs/references/http-websocket-apis/admin-api-methods/*/index.md"]},{"title":"Infrastructure","description":"Install, configure, and troubleshoot rippled and Clio servers.","includeFiles":["docs/infrastructure/**/*.*"],"excludeFiles":["docs/infrastructure/index.md","docs/infrastructure/*/index.md","docs/infrastructure/installation/build-run-rippled-in-reporting-mode.md","docs/infrastructure/configuration/data-retention/index.md","docs/infrastructure/configuration/server-modes/index.md"]},{"title":"Blog (2023+)","description":"Recent XRPL Blog posts (showing 2023 and newer).","includeFiles":["blog/2023/**/*.*","blog/2024/**/*.*","blog/2025/**/*.*","blog/2026/**/*.*"],"excludeFiles":[]},{"title":"Resources","description":"Developer resources and contribution guidelines.","includeFiles":["resources/**/*.*"],"excludeFiles":["resources/index.md"]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"xrpl-python-code-sample-conventions","__idx":0},"children":["XRPL Python Code Sample Conventions"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Code samples come in ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["two flavors"]}," with very different conventions. Identify which you're writing first."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Flavor"},"children":["Flavor"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Filename pattern"},"children":["Filename pattern"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Audience"},"children":["Audience"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Priority"},"children":["Priority"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Tutorial"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["<verb>_<thing>.py"]}," (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["create_loan_broker.py"]},")"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["A dev reading & learning the protocol"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Clarity over speed"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Setup"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["<topic>_setup.py"]}," (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["lending_setup.py"]},")"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["A dev who never opens this file — runs to prep network data (accounts, tokens, etc.) for all tutorials in the subject folder"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Speed over clarity"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If a file isn't clearly one or the other, prompt the user for clarity."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"style","__idx":1},"children":["Style"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"formatting","__idx":2},"children":["Formatting"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["4-space indent"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Double quotes"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Trailing commas on multi-line collections and call args"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"naming","__idx":3},"children":["Naming"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["File names: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["snake_case"]}," (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["create_loan.py"]},")"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Variables: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["snake_case"]}," — ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["loan_broker"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mpt_id"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["vault_id"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["loan_broker_id"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["credential_issuer"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Transaction model fields: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["snake_case"]}," per ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl-py"]}," (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["account="]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["vault_id="]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["management_fee_rate="]},") — ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl-py"]}," handles the PascalCase translation on the wire"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Setup JSON keys: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["snake_case"]}," (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["loan_broker"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["credential_issuer"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mpt_id"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["vault_id"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["loan_broker_id"]},")"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"structure","__idx":4},"children":["Structure"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"folder-layout","__idx":5},"children":["Folder layout"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Each code sample lives at ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["_code-samples/<topic>/py/"]},":"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"_code-samples/<topic>/py/\n├── README.md\n├── requirements.txt\n├── <topic>_setup.py        # Optional — runs once to prep network state\n├── <topic>_setup.json      # Auto-generated by the setup script and is gitignored\n└── <verb>_<thing>.py       # Tutorial scripts (one per user action)\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"readme","__idx":6},"children":["README"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["README.md"]}," is the entry point for a reader running the samples."]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Title: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["# <Topic> Examples (Python)"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["One-sentence description listing what the directory demonstrates"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["## Setup"]}," section with a single fenced block showing venv creation + ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["pip install -r requirements.txt"]},":"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"sh","header":{"controls":{"copy":{}}},"source":"python3 -m venv .venv\nsource .venv/bin/activate\npip install -r requirements.txt\n","lang":"sh"},"children":[]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":4},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["One ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["##"]}," section per tutorial script, in the order a reader should run them:"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Heading describes the action (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["## Create a Loan Broker"]},"), not the filename"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Fenced ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sh"]}," block with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["python3 <file>.py"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["One-sentence summary of what the script will output"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Fenced ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sh"]}," block showing actual expected console output (real addresses, tx IDs, JSON dumps — captured from a successful sample code run)"]}]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":5},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["---"]}," separator between tutorial sections"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The expected-output blocks document the golden path. Update them when a script's output format changes."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"requirementstxt","__idx":7},"children":["requirements.txt"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Minimal — pin only what's needed:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"xrpl-py>=<latest-stable>\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Add other deps only when a sample requires them."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"tutorial-files","__idx":8},"children":["Tutorial files"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Sync API only"]}," — ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.clients.JsonRpcClient"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.transaction.submit_and_wait"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.wallet.Wallet"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.wallet.generate_faucet_wallet"]},". No ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["asyncio"]},", no ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["main()"]}," wrapper, no ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["if __name__ == \"__main__\":"]}," — scripts run top-to-bottom and exit."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"structure-1","__idx":9},"children":["Structure"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Multi-line ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["# IMPORTANT:"]}," header explaining what the script demonstrates and any preconditions (e.g., \"uses an existing account that has a PRIVATE vault\")"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Imports — stdlib first, blank line, then ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl"]}," imports"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Set up the client:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"# Set up client ----------------------\nclient = JsonRpcClient(\"https://s.devnet.rippletest.net:51234\")\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":4},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["(Optional) If the tutorial is using setup script data:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"# This step checks for the necessary setup data to run the lending tutorials.\n# If missing, lending_setup.py will generate the data.\nif not os.path.exists(\"lending_setup.json\"):\n    print(\"\\n=== Lending tutorial data doesn't exist. Running setup script... ===\\n\")\n    subprocess.run([sys.executable, \"lending_setup.py\"], check=True)\n\n# Load preconfigured accounts and vault_id.\nwith open(\"lending_setup.json\") as f:\n    setup_data = json.load(f)\n\n# You can replace these values with your own.\nloan_broker = Wallet.from_seed(setup_data[\"loan_broker\"][\"seed\"])\nvault_id = setup_data[\"vault_id\"]\n\nprint(f\"\\nLoan broker/vault owner address: {loan_broker.address}\")\nprint(f\"Vault ID: {vault_id}\")\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":5},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["(Optional) If no setup data is used, fund new wallets for the tutorial."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"wallet = generate_faucet_wallet(client)\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Funding multiple wallets requires sequential calls."," ","6. Tutorial code steps."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"tutorial-code-step-guide","__idx":10},"children":["Tutorial code step guide"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Before each major step, add a comment and print a section banner."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Build transactions as ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl-py"]}," model instances and print the wire form before submitting:",{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"# Prepare LoanBrokerSet transaction ----------------------\nprint(\"\\n=== Preparing LoanBrokerSet transaction ===\\n\")\nloan_broker_set_tx = LoanBrokerSet(\n    account=loan_broker.address,\n    vault_id=vault_id,\n    management_fee_rate=1000,\n)\n\nprint(json.dumps(loan_broker_set_tx.to_xrpl(), indent=2))\n","lang":"python"},"children":[]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Submit with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["submit_and_wait"]}," and handle results by checking for ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["tesSUCCESS"]}," and exiting on failure:",{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"# Submit, sign, and wait for validation ----------------------\nprint(\"\\n=== Submitting LoanBrokerSet transaction ===\\n\")\nsubmit_response = submit_and_wait(loan_broker_set_tx, client, loan_broker)\n\nif submit_response.result[\"meta\"][\"TransactionResult\"] != \"tesSUCCESS\":\n    result_code = submit_response.result[\"meta\"][\"TransactionResult\"]\n    print(f\"Error: Unable to create loan broker: {result_code}\")\n    sys.exit(1)\n\nprint(\"Loan broker created successfully!\")\n","lang":"python"},"children":[]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Extract metadata relevant to the tutorial:",{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"# Extract loan broker information from the transaction result\nprint(\"\\n=== Loan Broker Information ===\\n\")\nloan_broker_node = next(\n    node for node in submit_response.result[\"meta\"][\"AffectedNodes\"]\n    if node.get(\"CreatedNode\", {}).get(\"LedgerEntryType\") == \"LoanBroker\"\n)\nprint(f\"LoanBroker ID: {loan_broker_node['CreatedNode']['LedgerIndex']}\")\nprint(f\"LoanBroker Psuedo-Account Address: {loan_broker_node['CreatedNode']['NewFields']['Account']}\")\n","lang":"python"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"setup-files","__idx":11},"children":["Setup files"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Async API only"]}," — ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.asyncio.clients.AsyncWebsocketClient"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.asyncio.wallet.generate_faucet_wallet"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.asyncio.transaction"]}," (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["submit_and_wait"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["autofill"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sign"]},"). Wrap in ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["async def main():"]}," + ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["async with AsyncWebsocketClient(WSS_URL) as client:"]},", and call ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["asyncio.run(main())"]}," at the bottom."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["WebSocket endpoints: Devnet (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["wss://s.devnet.rippletest.net:51233"]},") or Testnet (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["wss://s.altnet.rippletest.net:51233"]},")."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"speed-first-patterns-when-possible","__idx":12},"children":["Speed-first patterns when possible"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Run independent transactions concurrently with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["await asyncio.gather(...)"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["When fanning out parallel transactions from the same account, batch them first via ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TicketCreate(ticket_count=N)"]},", then pass ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sequence=0"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ticket_sequence=..."]}," on each parallel tx"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Destructure gather results: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["loan_broker, borrower = await asyncio.gather(generate_faucet_wallet(client), generate_faucet_wallet(client))"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Group ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.models"]}," imports into a single alphabetized parenthesized block"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"setup-code-guide","__idx":13},"children":["Setup code guide"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Top comment: single line, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["# Setup script for <topic> tutorials"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Only output is a carriage-return progress indicator: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["print(\"Setting up tutorial: N/D\", end=\"\\r\")"]}," between phases, where N is the step number and D is the total steps"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["No ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["=== Section ==="]}," banners, no transaction dumps — the reader never sees this file's output beyond the progress counter"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Section comments in code are short: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["# Section description"]}," (no dash visual)"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"output-file","__idx":14},"children":["Output file"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["At the end, write all data the tutorials will need:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"setup_data = {\n    \"description\": \"This file is auto-generated by lending_setup.py. It stores XRPL account info for use in lending protocol tutorials.\",\n    \"loan_broker\": {\n        \"address\": loan_broker.address,\n        \"seed\": loan_broker.seed,\n    },\n    \"domain_id\": domain_id,\n    \"mpt_id\": mpt_id,\n}\n\nwith open(\"lending_setup.json\", \"w\") as f:\n    json.dump(setup_data, f, indent=2)\n","lang":"python"},"children":[]}]},"headings":[{"value":"XRPL Python Code Sample Conventions","id":"xrpl-python-code-sample-conventions","depth":1},{"value":"Style","id":"style","depth":2},{"value":"Formatting","id":"formatting","depth":3},{"value":"Naming","id":"naming","depth":3},{"value":"Structure","id":"structure","depth":2},{"value":"Folder layout","id":"folder-layout","depth":3},{"value":"README","id":"readme","depth":3},{"value":"requirements.txt","id":"requirementstxt","depth":3},{"value":"Tutorial files","id":"tutorial-files","depth":2},{"value":"Structure","id":"structure-1","depth":3},{"value":"Tutorial code step guide","id":"tutorial-code-step-guide","depth":3},{"value":"Setup files","id":"setup-files","depth":2},{"value":"Speed-first patterns when possible","id":"speed-first-patterns-when-possible","depth":3},{"value":"Setup code guide","id":"setup-code-guide","depth":3},{"value":"Output file","id":"output-file","depth":3}],"frontmatter":{"paths":["_code-samples/**/*.py"],"seo":{"title":"XRPL Python Code Sample Conventions"}},"editPage":{"to":"https://github.com/XRPLF/xrpl-dev-portal/tree/master/.claude/rules/python-code-samples.md"},"lastModified":"2026-06-05T19:13:01.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/ja/.claude/rules/python-code-samples","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}