<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>article Future-Proof Your Splunk Apps: Python 3 Essentials in Community Blog</title>
    <link>https://community.splunk.com/t5/Community-Blog/Future-Proof-Your-Splunk-Apps-Python-3-Essentials/ba-p/752183</link>
    <description>&lt;P&gt;&lt;SPAN&gt;A critical update for all Splunk app developers: Python 3.9 is now the default interpreter in Splunk Enterprise 9.4 and beyond. The Developer Advisory and Support (DAS) team wants to make sure you're not just aware, but fully prepared for this shift. This isn't just about technical compliance; it's about unlocking new capabilities, enhancing security, and ensuring the longevity of your Splunk applications. In this post, we'll dive deep into the essential best practices for Python 3 development and lay out a clear path for migrating your existing Python 2 apps. Let's get your Splunk solutions ready for what's next.&lt;/SPAN&gt;&lt;/P&gt;&lt;H2&gt;&lt;STRONG&gt;Why Python 3 is Crucial for Your Splunk Apps:&lt;/STRONG&gt;&lt;/H2&gt;&lt;P&gt;&lt;SPAN&gt;The transition to Python 3 isn't merely an option; it's &lt;/SPAN&gt;&lt;STRONG&gt;essential &lt;/STRONG&gt;&lt;SPAN&gt;for the longevity and security of your Splunk applications. Python 2 is officially end-of-life and no longer receives critical security updates, leaving your apps vulnerable. Here's why embracing Python 3 is a must-do:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Enhanced Security: &lt;/STRONG&gt;&lt;SPAN&gt;Python 3 offers improved security features and practices, safeguarding your Splunk environment.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Long-Term Support &amp;amp; Compatibility:&lt;/STRONG&gt;&lt;SPAN&gt; Python 3 is the future. Ensuring your apps are Python 3 compatible guarantees long-term support and seamless compatibility with future Splunk releases.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Modern Language Features:&lt;/STRONG&gt;&lt;SPAN&gt; Benefit from numerous language improvements, performance enhancements, and new libraries that streamline your development process and boost app functionality.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Compliance:&lt;/STRONG&gt;&lt;SPAN&gt; Many organizations now require actively supported software. Adopting Python 3 helps you meet these vital compliance necessities.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;&lt;H2&gt;&lt;STRONG&gt;Strategies for Migrating Existing Python 2 Apps:&lt;/STRONG&gt;&lt;/H2&gt;&lt;P&gt;&lt;SPAN&gt;Migrating an existing Splunk app from Python 2 to Python 3 requires a systematic approach. Follow these key steps and considerations to ensure a smooth transition:&lt;/SPAN&gt;&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;1. Assess Your Current Apps:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Identify Python 2 Dependencies: &lt;/STRONG&gt;&lt;SPAN&gt;Pinpoint all Python scripts, modular inputs, custom commands, and libraries within your Splunk apps that may still be relying on Python 2.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Utilize the Monitoring Console:&lt;/STRONG&gt;&lt;SPAN&gt; Leverage the Monitoring Console within Splunk Enterprise to gain insights into your Python 3 migration readiness. It provides valuable visibility into components that may be impacted by the Python 3 transition, helping you identify areas requiring immediate attention.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;AppInspect: &lt;/STRONG&gt;&lt;SPAN&gt;Before deployment, use the &lt;/SPAN&gt;&lt;STRONG&gt;Splunk AppInspect &lt;/STRONG&gt;&lt;SPAN&gt;tool (CLI or API) to confidently check for features that require revision for Python 3 compatibility. This reduces review time and ensures adherence to Splunk's rigorous standards.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;&lt;STRONG&gt;2. Understand Common Python 2 to 3 Changes:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Print Statements&lt;/STRONG&gt;&lt;SPAN&gt;: Remember, print is a function in Python 3, not a statement. E.g., &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;print "Hello" &lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;becomes &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;print("Hello")&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;xrange() vs. range():&lt;/STRONG&gt; &lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;xrange()&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;is removed in Python 3; &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;range()&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; now behaves like &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;xrange()&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; in Python 2.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Dictionary Iteration: &lt;/STRONG&gt;&lt;SPAN&gt;Methods like &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;dict.iteritems() &lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;are replaced by &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;dict.items()&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; which return views instead of lists.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;file() function:&lt;/STRONG&gt;&lt;SPAN&gt; Use&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt; open()&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; instead.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;os.path.walk(): &lt;/STRONG&gt;&lt;SPAN&gt;Replaced by &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;os.walk()&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Division Operator:&lt;/STRONG&gt;&lt;SPAN&gt; Be aware of changes in integer division behavior..&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;String Handling: &lt;/STRONG&gt;&lt;SPAN&gt;Unicode strings are the default in Python 3.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;For a comprehensive list of changes, please refer to the Splunk documentation on Python 3 migration resources and Python code compatibility.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;&lt;STRONG&gt;3. Implement Dual-Compatibility (Optional but Recommended for Transition):&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;If your apps need to run on both Python 2 and Python 3 environments during a transition period, consider using compatibility libraries like &lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;Six&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;Python-future&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;. These libraries help you write code that functions across both versions. &lt;/SPAN&gt;&lt;STRONG&gt;Ensure&lt;/STRONG&gt;&lt;SPAN&gt; you import them as needed and do not distribute another version of these libraries with your app.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;&lt;STRONG&gt;4. Testing and Validation:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Thorough Testing:&lt;/STRONG&gt;&lt;SPAN&gt; After making changes, &lt;/SPAN&gt;&lt;STRONG&gt;rigorously&lt;/STRONG&gt;&lt;SPAN&gt; test your apps in a Python 3 environment. Splunk strongly recommends testing and validating your apps for compatibility.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Test Environment: Always validate&lt;/STRONG&gt;&lt;SPAN&gt; the upgrade in a dedicated test environment before deploying to production. This is a non-negotiable step to prevent unexpected issues.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H2&gt;&lt;STRONG&gt;Developing New Splunk Apps with Python 3 Best Practices:&lt;/STRONG&gt;&lt;/H2&gt;&lt;P&gt;&lt;SPAN&gt;When building new Splunk apps or components, &lt;/SPAN&gt;&lt;STRONG&gt;always target Python 3 from the start&lt;/STRONG&gt;&lt;SPAN&gt;. For detailed development guidance, refer to the Splunk documentation on Python 3 migration and development.&lt;/SPAN&gt;&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;1. Leverage the Splunk Enterprise SDK for Python:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;The Splunk Enterprise SDK for Python is compatible with Python 3. It provides robust library code to programmatically interact with the Splunk platform, simplifying tasks like searching, managing configurations, and creating data inputs.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;&lt;STRONG&gt;2. Structuring Your Python Code:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;bin Directory:&lt;/STRONG&gt;&lt;SPAN&gt; Store any Python files referenced by a &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;.conf&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; file (like custom commands or modular inputs) in your app's&amp;nbsp;&lt;FONT face="courier new,courier"&gt;/&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;bin&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; directory.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;lib Directory: &lt;/STRONG&gt;&lt;SPAN&gt;For external Python dependencies, ensure they are stored in the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;/&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;lib&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; directory, not &lt;FONT face="courier new,courier"&gt;/&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;bin&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;&lt;STRONG&gt;3. Creating Python 3 Custom Commands:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;Custom search commands extend Splunk Search Processing Language (SPL) using external Python scripts.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;In your &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;commands.conf&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; file, for apps compatible with Splunk Enterprise 8.0 and higher, you &lt;/SPAN&gt;&lt;STRONG&gt;must&lt;/STRONG&gt;&lt;SPAN&gt; add &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;python.version = python3&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; to specify that the Python script runs in Python 3.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;For more details on crafting custom search commands, refer to the Splunk developer documentation.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;&lt;STRONG&gt;4. Developing Python 3 Modular Inputs:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;Modular inputs allow you to bring data into Splunk from custom sources.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Use the Splunk Enterprise SDK for Python to create modular inputs by inheriting from &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;splunklib.modularinput.script&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Define a scheme for introspection and override methods like &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;get_scheme&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;validate_input&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;, and &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;stream_events&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;&lt;STRONG&gt;5. Logging and Debugging:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Implement robust logging&lt;/STRONG&gt;&lt;SPAN&gt; within your Python scripts to &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;splunkd.log&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; for easier troubleshooting. For modular inputs, use &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;EventWriter.log&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The transition to Python 3 is a &lt;/SPAN&gt;&lt;STRONG&gt;significant and necessary step&lt;/STRONG&gt;&lt;SPAN&gt; for all Splunk app developers. By understanding the core changes, utilizing Splunk's powerful migration tools like the Monitoring Console and AppInspect, and adopting these best practices for new development, you can ensure your Splunk applications remain secure, performant, and fully supported.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The Developer Advisory and Support (DAS) team is committed to assisting you and ensuring you have the guidance and resources needed to build and migrate your Splunk applications successfully. Don’t hesitate to reach out to us at &lt;/SPAN&gt;&lt;STRONG&gt;devsupport-splunk@cisco.com&lt;/STRONG&gt;&lt;SPAN&gt;. We are here to empower you and ensure no developer is left behind in building innovative Splunk solutions.&lt;/SPAN&gt;&lt;/P&gt;&lt;H2&gt;&lt;STRONG&gt;Web references:&lt;/STRONG&gt;&lt;/H2&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://dev.splunk.com/enterprise/docs/developapps/testvalidate/appinspect/" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Validate using AppInspect&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.4.2/Python3Migration/Resources" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Resources for Python 3 migration&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.4.2/Python3Migration/PythonCompatibility" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Python Code Compatibility&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.4.2/Python3Migration/PythonDevelopment" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Python 3 migration - Development with Splunk Enterprise&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://docs.splunk.com/Documentation/PythonSDK" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Splunk Enterprise SDK for Python reference&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.4.2/AdvancedDev/ModInputsScripts" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Create Modular Inputs&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://dev.splunk.com/enterprise/docs/devtools/customsearchcommands/" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Custom Search Commands&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
    <pubDate>Thu, 28 Aug 2025 16:00:00 GMT</pubDate>
    <dc:creator>jasongreen</dc:creator>
    <dc:date>2025-08-28T16:00:00Z</dc:date>
    <item>
      <title>Future-Proof Your Splunk Apps: Python 3 Essentials</title>
      <link>https://community.splunk.com/t5/Community-Blog/Future-Proof-Your-Splunk-Apps-Python-3-Essentials/ba-p/752183</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Ready for Python 3? With Splunk 9.4+ defaulting to Python 3.9, the DAS team shares essential best practices and migration strategies to future-proof your Splunk apps. Dive in!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Aug 2025 16:00:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Community-Blog/Future-Proof-Your-Splunk-Apps-Python-3-Essentials/ba-p/752183</guid>
      <dc:creator>jasongreen</dc:creator>
      <dc:date>2025-08-28T16:00:00Z</dc:date>
    </item>
  </channel>
</rss>

