{"library":"pynetdicom","title":"pynetdicom: DICOM Networking Protocol","description":"pynetdicom is a Python implementation of the DICOM networking protocol, allowing developers to create DICOM Service Class Users (SCUs) and Service Class Providers (SCPs). It handles DICOM association negotiation, message exchange, and event management. The current version is 3.0.4, and it generally follows a release cadence tied to bug fixes and minor feature enhancements, with major versions introducing significant architectural changes.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pynetdicom","pip install pynetdicom[scu]","pip install pynetdicom[scp]","pip install pynetdicom[tls]"],"cli":null},"imports":["from pynetdicom import AE","from pynetdicom import evt","from pynetdicom.presentation import VerificationPresentationContexts","from pynetdicom.presentation import StoragePresentationContexts"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from pynetdicom import AE, VerificationPresentationContexts\nimport logging\nimport os\n\n# Configure logging to see association details (optional but recommended)\nlogging.basicConfig(level=logging.INFO)\n\n# Initialise the Application Entity (AE) for the SCU\n# AE Titles must be bytes objects (e.g., b'MY_AE_TITLE')\nscu_ae_title = os.environ.get('PYNETDICOM_AE_TITLE_SCU', 'PYNETDICOM_SCU').encode('utf-8')\nae = AE(ae_title=scu_ae_title)\n\n# Add a supported presentation context for the Verification SOP Class (C-ECHO)\n# This tells the AE what services it can request/provide.\nae.add_supported_context(VerificationPresentationContexts[0])\n\n# Define the target SCP's details (can be read from environment variables for flexibility)\ntarget_ip = os.environ.get('PYNETDICOM_TARGET_IP', '127.0.0.1')\ntarget_port = int(os.environ.get('PYNETDICOM_TARGET_PORT', '11112'))\ntarget_ae_title = os.environ.get('PYNETDICOM_TARGET_AE_TITLE', 'ANY_SCP_AE').encode('utf-8')\n\nprint(f\"\\nAttempting to associate {scu_ae_title.decode()} with {target_ae_title.decode()} at {target_ip}:{target_port}...\")\nprint(\"NOTE: Ensure a DICOM SCP is running at this address and listening on the specified port.\")\n\n# Attempt to establish an association with the remote AE (SCP)\nassoc = ae.associate(target_ip, target_port, ae_title=target_ae_title)\n\nif assoc.is_established:\n    print('\\nAssociation established with peer.')\n    # Send a C-ECHO request to verify connection\n    status = assoc.send_c_echo()\n    print(f'C-ECHO response status: {status}')\n    # Release the association gracefully\n    assoc.release()\n    print('Association released.')\nelse:\n    print('\\nAssociation rejected, aborted or never connected.')\n\n# Clean up any resources (e.g., server threads) associated with the AE\nae.shutdown()\n","lang":"python","description":"This quickstart demonstrates how to create a simple DICOM Service Class User (SCU) that establishes an association with a remote DICOM Service Class Provider (SCP) and sends a C-ECHO request (a DICOM 'ping'). It uses environment variables for configuration, making it runnable without modification.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}