{"library":"pysnc","title":"Python SNC (ServiceNow) API","description":"PySNC is a Python interface for the ServiceNow REST and Table APIs, designed to mimic the familiar GlideRecord interface with Pythonic support. It provides robust features for interacting with ServiceNow instances, including synchronous and asynchronous operations, OAuth 2.0 Client Credentials Grant Flow, mTLS support, and built-in retry mechanisms for common error codes. The library is actively maintained with a positive release cadence.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install pysnc","pip install pysnc[asyncio]"],"cli":null},"imports":["from pysnc import ServiceNowClient","from pysnc.asyncio import AsyncServiceNowClient","from pysnc.oauth2 import ServiceNowPasswordGrantFlow"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom pysnc import ServiceNowClient\n\n# Configure environment variables for secure access\nSN_INSTANCE = os.environ.get('SN_INSTANCE', 'your_instance.service-now.com')\nSN_USERNAME = os.environ.get('SN_USERNAME', 'your_username')\nSN_PASSWORD = os.environ.get('SN_PASSWORD', 'your_password')\n\nif not all([SN_INSTANCE, SN_USERNAME, SN_PASSWORD]):\n    print(\"Please set SN_INSTANCE, SN_USERNAME, and SN_PASSWORD environment variables.\")\n    exit(1)\n\ntry:\n    # Initialize the ServiceNow client with basic authentication\n    client = ServiceNowClient(SN_INSTANCE, (SN_USERNAME, SN_PASSWORD))\n\n    # Create a GlideRecord object for the 'incident' table\n    gr = client.GlideRecord('incident')\n\n    # Add a query condition (e.g., active incidents)\n    gr.add_query('active', 'true')\n    gr.add_limit(5) # Limit results for demonstration\n\n    # Execute the query\n    gr.query()\n\n    # Iterate through the results (Pythonic iteration is recommended)\n    print(f\"Found {gr.get_row_count()} active incidents:\")\n    for record in gr:\n        print(f\"  Incident Number: {record.number}, Short Description: {record.short_description}\")\n\n    # Example of getting a single record by sys_id\n    if gr.get_row_count() > 0:\n        first_sys_id = gr.next().sys_id # Using .next() here for specific record access\n        single_record = client.GlideRecord('incident')\n        if single_record.get(first_sys_id):\n            print(f\"\\nRetrieved single incident: {single_record.number}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize the `ServiceNowClient` using environment variables for credentials, create a `GlideRecord` object, add a query, execute it, and iterate through the results. It also shows how to fetch a single record by its `sys_id`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}