Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
plistlib.html567 linesDownload Raw Back to docs
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4  <head>5    <meta charset="utf-8" />6    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="plistlib — Generate and parse Apple .plist files" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/plistlib.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/plistlib.py This module provides an interface for reading and writing the “property list” files used by Apple, primarily on macOS and iOS. This module supports both binary and XML ..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_plistlib_5bdc695a.png" />15<meta property="og:image:alt" content="Source code: Lib/plistlib.py This module provides an interface for reading and writing the “property list” files used by Apple, primarily on macOS and iOS. This module supports both binary and XML ..." />16<meta name="description" content="Source code: Lib/plistlib.py This module provides an interface for reading and writing the “property list” files used by Apple, primarily on macOS and iOS. This module supports both binary and XML ..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>plistlib — Generate and parse Apple .plist files &#8212; Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21    22    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23    <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25    <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26    <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27    28    <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29    <script src="../_static/doctools.js?v=9bcbadda"></script>30    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31    <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32    33    <script src="../_static/sidebar.js"></script>34    35    <link rel="search" type="application/opensearchdescription+xml"36          title="Search within Python 3.15.0a6 documentation"37          href="../_static/opensearch.xml"/>38    <link rel="author" title="About these documents" href="../about.html" />39    <link rel="index" title="Index" href="../genindex.html" />40    <link rel="search" title="Search" href="../search.html" />41    <link rel="copyright" title="Copyright" href="../copyright.html" />42    <link rel="next" title="Cryptographic Services" href="crypto.html" />43    <link rel="prev" title="netrc — netrc file processing" href="netrc.html" />44    45      46      <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47      48      <link rel="canonical" href="https://docs.python.org/3/library/plistlib.html">49      50    51 52    53    <style>54      @media only screen {55        table.full-width-table {56            width: 100%;57        }58      }59    </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61    <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62            <script type="text/javascript" src="../_static/copybutton.js"></script>63            <script type="text/javascript" src="../_static/menu.js"></script>64            <script type="text/javascript" src="../_static/search-focus.js"></script>65            <script type="text/javascript" src="../_static/themetoggle.js"></script> 66            <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67            <meta name="readthedocs-addons-api-version" content="1">68 69  </head>70<body>71<div class="mobile-nav">72    <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73           aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74    <nav class="nav-content" role="navigation">75        <label for="menuToggler" class="toggler__label">76            <span></span>77        </label>78        <span class="nav-items-wrapper">79            <a href="https://www.python.org/" class="nav-logo">80                <img src="../_static/py.svg" alt="Python logo">81            </a>82            <span class="version_switcher_placeholder"></span>83            <form role="search" class="search" action="../search.html" method="get">84                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85                    <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>86                </svg>87                <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88                <input type="submit" value="Go">89            </form>90        </span>91    </nav>92    <div class="menu-wrapper">93        <nav class="menu" role="navigation" aria-label="main navigation">94            <div class="language_switcher_placeholder"></div>95            96<label class="theme-selector-label">97    Theme98    <select class="theme-selector" oninput="activateTheme(this.value)">99        <option value="auto" selected>Auto</option>100        <option value="light">Light</option>101        <option value="dark">Dark</option>102    </select>103</label>104  <div>105    <h3><a href="../contents.html">Table of Contents</a></h3>106    <ul>107<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code> — Generate and parse Apple <code class="docutils literal notranslate"><span class="pre">.plist</span></code> files</a><ul>108<li><a class="reference internal" href="#examples">Examples</a></li>109</ul>110</li>111</ul>112 113  </div>114  <div>115    <h4>Previous topic</h4>116    <p class="topless"><a href="netrc.html"117                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">netrc</span></code> — netrc file processing</a></p>118  </div>119  <div>120    <h4>Next topic</h4>121    <p class="topless"><a href="crypto.html"122                          title="next chapter">Cryptographic Services</a></p>123  </div>124  <script>125    document.addEventListener('DOMContentLoaded', () => {126        const title = document.querySelector('meta[property="og:title"]').content;127        const elements = document.querySelectorAll('.improvepage');128        const pageurl = window.location.href.split('?')[0];129        elements.forEach(element => {130            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));131            url.searchParams.set('pagetitle', title);132            url.searchParams.set('pageurl', pageurl);133            url.searchParams.set('pagesource', "library/plistlib.rst");134            element.href = url.toString();135        });136    });137  </script>138  <div role="note" aria-label="source link">139    <h3>This page</h3>140    <ul class="this-page-menu">141      <li><a href="../bugs.html">Report a bug</a></li>142      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>143      <li>144        <a href="https://github.com/python/cpython/blob/main/Doc/library/plistlib.rst?plain=1"145            rel="nofollow">Show source146        </a>147      </li>148      149    </ul>150  </div>151        </nav>152    </div>153</div>154 155  156    <div class="related" role="navigation" aria-label="Related">157      <h3>Navigation</h3>158      <ul>159        <li class="right" style="margin-right: 10px">160          <a href="../genindex.html" title="General Index"161             accesskey="I">index</a></li>162        <li class="right" >163          <a href="../py-modindex.html" title="Python Module Index"164             >modules</a> |</li>165        <li class="right" >166          <a href="crypto.html" title="Cryptographic Services"167             accesskey="N">next</a> |</li>168        <li class="right" >169          <a href="netrc.html" title="netrc — netrc file processing"170             accesskey="P">previous</a> |</li>171 172          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>173          <li><a href="https://www.python.org/">Python</a> &#187;</li>174          <li class="switchers">175            <div class="language_switcher_placeholder"></div>176            <div class="version_switcher_placeholder"></div>177          </li>178          <li>179              180          </li>181    <li id="cpython-language-and-version">182      <a href="../index.html">3.15.0a6 Documentation</a> &#187;183    </li>184 185          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>186          <li class="nav-item nav-item-2"><a href="fileformats.html" accesskey="U">File Formats</a> &#187;</li>187        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code> — Generate and parse Apple <code class="docutils literal notranslate"><span class="pre">.plist</span></code> files</a></li>188                <li class="right">189                    190 191    <div class="inline-search" role="search">192        <form class="inline-search" action="../search.html" method="get">193          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">194          <input type="submit" value="Go">195        </form>196    </div>197                     |198                </li>199            <li class="right">200<label class="theme-selector-label">201    Theme202    <select class="theme-selector" oninput="activateTheme(this.value)">203        <option value="auto" selected>Auto</option>204        <option value="light">Light</option>205        <option value="dark">Dark</option>206    </select>207</label> |</li>208            209      </ul>210    </div>    211 212    <div class="document">213      <div class="documentwrapper">214        <div class="bodywrapper">215          <div class="body" role="main">216            217  <section id="module-plistlib">218<span id="plistlib-generate-and-parse-apple-plist-files"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code> — Generate and parse Apple <code class="docutils literal notranslate"><span class="pre">.plist</span></code> files<a class="headerlink" href="#module-plistlib" title="Link to this heading">¶</a></h1>219<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/plistlib.py">Lib/plistlib.py</a></p>220<hr class="docutils" id="index-0" />221<p>This module provides an interface for reading and writing the “property list”222files used by Apple, primarily on macOS and iOS. This module supports both binary223and XML plist files.</p>224<p>The property list (<code class="docutils literal notranslate"><span class="pre">.plist</span></code>) file format is a simple serialization supporting225basic object types, like dictionaries, lists, numbers and strings.  Usually the226top level object is a dictionary.</p>227<p>To write out and to parse a plist file, use the <a class="reference internal" href="#plistlib.dump" title="plistlib.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump()</span></code></a> and228<a class="reference internal" href="#plistlib.load" title="plistlib.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">load()</span></code></a> functions.</p>229<p>To work with plist data in bytes or string objects, use <a class="reference internal" href="#plistlib.dumps" title="plistlib.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">dumps()</span></code></a>230and <a class="reference internal" href="#plistlib.loads" title="plistlib.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">loads()</span></code></a>.</p>231<p>Values can be strings, integers, floats, booleans, tuples, lists, dictionaries232(but only with string keys), <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>, <a class="reference internal" href="stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a>233or <a class="reference internal" href="datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.datetime</span></code></a> objects.</p>234<div class="versionchanged">235<p><span class="versionmodified changed">Changed in version 3.4: </span>New API, old API deprecated.  Support for binary format plists added.</p>236</div>237<div class="versionchanged">238<p><span class="versionmodified changed">Changed in version 3.8: </span>Support added for reading and writing <a class="reference internal" href="#plistlib.UID" title="plistlib.UID"><code class="xref py py-class docutils literal notranslate"><span class="pre">UID</span></code></a> tokens in binary plists as used239by NSKeyedArchiver and NSKeyedUnarchiver.</p>240</div>241<div class="versionchanged">242<p><span class="versionmodified changed">Changed in version 3.9: </span>Old API removed.</p>243</div>244<div class="admonition seealso">245<p class="admonition-title">See also</p>246<dl class="simple">247<dt><a class="reference external" href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/PropertyLists/">PList manual page</a></dt><dd><p>Apple’s documentation of the file format.</p>248</dd>249</dl>250</div>251<p>This module defines the following functions:</p>252<dl class="py function">253<dt class="sig sig-object py" id="plistlib.load">254<span class="sig-prename descclassname"><span class="pre">plistlib.</span></span><span class="sig-name descname"><span class="pre">load</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fp</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">fmt</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dict_type</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">dict</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">aware_datetime</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#plistlib.load" title="Link to this definition">¶</a></dt>255<dd><p>Read a plist file. <em>fp</em> should be a readable and binary file object.256Return the unpacked root object (which usually is a257dictionary).</p>258<p>The <em>fmt</em> is the format of the file and the following values are valid:</p>259<ul class="simple">260<li><p><a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-data docutils literal notranslate"><span class="pre">None</span></code></a>: Autodetect the file format</p></li>261<li><p><a class="reference internal" href="#plistlib.FMT_XML" title="plistlib.FMT_XML"><code class="xref py py-data docutils literal notranslate"><span class="pre">FMT_XML</span></code></a>: XML file format</p></li>262<li><p><a class="reference internal" href="#plistlib.FMT_BINARY" title="plistlib.FMT_BINARY"><code class="xref py py-data docutils literal notranslate"><span class="pre">FMT_BINARY</span></code></a>: Binary plist format</p></li>263</ul>264<p>The <em>dict_type</em> is the type used for dictionaries that are read from the265plist file.</p>266<p>When <em>aware_datetime</em> is true, fields with type <code class="docutils literal notranslate"><span class="pre">datetime.datetime</span></code> will267be created as <a class="reference internal" href="datetime.html#datetime-naive-aware"><span class="std std-ref">aware object</span></a>, with268<code class="xref py py-attr docutils literal notranslate"><span class="pre">tzinfo</span></code> as <a class="reference internal" href="datetime.html#datetime.UTC" title="datetime.UTC"><code class="xref py py-const docutils literal notranslate"><span class="pre">datetime.UTC</span></code></a>.</p>269<p>XML data for the <a class="reference internal" href="#plistlib.FMT_XML" title="plistlib.FMT_XML"><code class="xref py py-data docutils literal notranslate"><span class="pre">FMT_XML</span></code></a> format is parsed using the Expat parser270from <a class="reference internal" href="pyexpat.html#module-xml.parsers.expat" title="xml.parsers.expat: An interface to the Expat non-validating XML parser."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.parsers.expat</span></code></a> – see its documentation for possible271exceptions on ill-formed XML.  Unknown elements will simply be ignored272by the plist parser.</p>273<p>The parser raises <a class="reference internal" href="#plistlib.InvalidFileException" title="plistlib.InvalidFileException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidFileException</span></code></a> when the file cannot be parsed.</p>274<div class="versionadded">275<p><span class="versionmodified added">Added in version 3.4.</span></p>276</div>277<div class="versionchanged">278<p><span class="versionmodified changed">Changed in version 3.13: </span>The keyword-only parameter <em>aware_datetime</em> has been added.</p>279</div>280</dd></dl>281 282<dl class="py function">283<dt class="sig sig-object py" id="plistlib.loads">284<span class="sig-prename descclassname"><span class="pre">plistlib.</span></span><span class="sig-name descname"><span class="pre">loads</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">fmt</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dict_type</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">dict</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">aware_datetime</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#plistlib.loads" title="Link to this definition">¶</a></dt>285<dd><p>Load a plist from a bytes or string object. See <a class="reference internal" href="#plistlib.load" title="plistlib.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">load()</span></code></a> for an286explanation of the keyword arguments.</p>287<div class="versionadded">288<p><span class="versionmodified added">Added in version 3.4.</span></p>289</div>290<div class="versionchanged">291<p><span class="versionmodified changed">Changed in version 3.13: </span><em>data</em> can be a string when <em>fmt</em> equals <a class="reference internal" href="#plistlib.FMT_XML" title="plistlib.FMT_XML"><code class="xref py py-data docutils literal notranslate"><span class="pre">FMT_XML</span></code></a>.</p>292</div>293</dd></dl>294 295<dl class="py function">296<dt class="sig sig-object py" id="plistlib.dump">297<span class="sig-prename descclassname"><span class="pre">plistlib.</span></span><span class="sig-name descname"><span class="pre">dump</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fp</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">fmt</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">FMT_XML</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sort_keys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">skipkeys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">aware_datetime</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#plistlib.dump" title="Link to this definition">¶</a></dt>298<dd><p>Write <em>value</em> to a plist file. <em>fp</em> should be a writable, binary299file object.</p>300<p>The <em>fmt</em> argument specifies the format of the plist file and can be301one of the following values:</p>302<ul class="simple">303<li><p><a class="reference internal" href="#plistlib.FMT_XML" title="plistlib.FMT_XML"><code class="xref py py-data docutils literal notranslate"><span class="pre">FMT_XML</span></code></a>: XML formatted plist file</p></li>304<li><p><a class="reference internal" href="#plistlib.FMT_BINARY" title="plistlib.FMT_BINARY"><code class="xref py py-data docutils literal notranslate"><span class="pre">FMT_BINARY</span></code></a>: Binary formatted plist file</p></li>305</ul>306<p>When <em>sort_keys</em> is true (the default) the keys for dictionaries will be307written to the plist in sorted order, otherwise they will be written in308the iteration order of the dictionary.</p>309<p>When <em>skipkeys</em> is false (the default) the function raises <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>310when a key of a dictionary is not a string, otherwise such keys are skipped.</p>311<p>When <em>aware_datetime</em> is true and any field with type <code class="docutils literal notranslate"><span class="pre">datetime.datetime</span></code>312is set as an <a class="reference internal" href="datetime.html#datetime-naive-aware"><span class="std std-ref">aware object</span></a>, it will convert to313UTC timezone before writing it.</p>314<p>A <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> will be raised if the object is of an unsupported type or315a container that contains objects of unsupported types.</p>316<p>An <a class="reference internal" href="exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a> will be raised for integer values that cannot317be represented in (binary) plist files.</p>318<div class="versionadded">319<p><span class="versionmodified added">Added in version 3.4.</span></p>320</div>321<div class="versionchanged">322<p><span class="versionmodified changed">Changed in version 3.13: </span>The keyword-only parameter <em>aware_datetime</em> has been added.</p>323</div>324</dd></dl>325 326<dl class="py function">327<dt class="sig sig-object py" id="plistlib.dumps">328<span class="sig-prename descclassname"><span class="pre">plistlib.</span></span><span class="sig-name descname"><span class="pre">dumps</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">fmt</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">FMT_XML</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sort_keys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">skipkeys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">aware_datetime</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#plistlib.dumps" title="Link to this definition">¶</a></dt>329<dd><p>Return <em>value</em> as a plist-formatted bytes object. See330the documentation for <a class="reference internal" href="#plistlib.dump" title="plistlib.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump()</span></code></a> for an explanation of the keyword331arguments of this function.</p>332<div class="versionadded">333<p><span class="versionmodified added">Added in version 3.4.</span></p>334</div>335</dd></dl>336 337<p>The following classes are available:</p>338<dl class="py class">339<dt class="sig sig-object py" id="plistlib.UID">340<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">plistlib.</span></span><span class="sig-name descname"><span class="pre">UID</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#plistlib.UID" title="Link to this definition">¶</a></dt>341<dd><p>Wraps an <a class="reference internal" href="functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>.  This is used when reading or writing NSKeyedArchiver342encoded data, which contains UID (see PList manual).</p>343<dl class="py attribute">344<dt class="sig sig-object py" id="plistlib.UID.data">345<span class="sig-name descname"><span class="pre">data</span></span><a class="headerlink" href="#plistlib.UID.data" title="Link to this definition">¶</a></dt>346<dd><p>Int value of the UID.  It must be in the range <code class="docutils literal notranslate"><span class="pre">0</span> <span class="pre">&lt;=</span> <span class="pre">data</span> <span class="pre">&lt;</span> <span class="pre">2**64</span></code>.</p>347</dd></dl>348 349<div class="versionadded">350<p><span class="versionmodified added">Added in version 3.8.</span></p>351</div>352</dd></dl>353 354<p>The following constants are available:</p>355<dl class="py data">356<dt class="sig sig-object py" id="plistlib.FMT_XML">357<span class="sig-prename descclassname"><span class="pre">plistlib.</span></span><span class="sig-name descname"><span class="pre">FMT_XML</span></span><a class="headerlink" href="#plistlib.FMT_XML" title="Link to this definition">¶</a></dt>358<dd><p>The XML format for plist files.</p>359<div class="versionadded">360<p><span class="versionmodified added">Added in version 3.4.</span></p>361</div>362</dd></dl>363 364<dl class="py data">365<dt class="sig sig-object py" id="plistlib.FMT_BINARY">366<span class="sig-prename descclassname"><span class="pre">plistlib.</span></span><span class="sig-name descname"><span class="pre">FMT_BINARY</span></span><a class="headerlink" href="#plistlib.FMT_BINARY" title="Link to this definition">¶</a></dt>367<dd><p>The binary format for plist files</p>368<div class="versionadded">369<p><span class="versionmodified added">Added in version 3.4.</span></p>370</div>371</dd></dl>372 373<p>The module defines the following exceptions:</p>374<dl class="py exception">375<dt class="sig sig-object py" id="plistlib.InvalidFileException">376<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">plistlib.</span></span><span class="sig-name descname"><span class="pre">InvalidFileException</span></span><a class="headerlink" href="#plistlib.InvalidFileException" title="Link to this definition">¶</a></dt>377<dd><p>Raised when a file cannot be parsed.</p>378<div class="versionadded">379<p><span class="versionmodified added">Added in version 3.4.</span></p>380</div>381</dd></dl>382 383<section id="examples">384<h2>Examples<a class="headerlink" href="#examples" title="Link to this heading">¶</a></h2>385<p>Generating a plist:</p>386<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">datetime</span>387<span class="kn">import</span><span class="w"> </span><span class="nn">plistlib</span>388 389<span class="n">pl</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>390    <span class="n">aString</span> <span class="o">=</span> <span class="s2">&quot;Doodah&quot;</span><span class="p">,</span>391    <span class="n">aList</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;A&quot;</span><span class="p">,</span> <span class="s2">&quot;B&quot;</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mf">32.1</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]],</span>392    <span class="n">aFloat</span> <span class="o">=</span> <span class="mf">0.1</span><span class="p">,</span>393    <span class="n">anInt</span> <span class="o">=</span> <span class="mi">728</span><span class="p">,</span>394    <span class="n">aDict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>395        <span class="n">anotherString</span> <span class="o">=</span> <span class="s2">&quot;&lt;hello &amp; hi there!&gt;&quot;</span><span class="p">,</span>396        <span class="n">aThirdString</span> <span class="o">=</span> <span class="s2">&quot;M</span><span class="se">\xe4</span><span class="s2">ssig, Ma</span><span class="se">\xdf</span><span class="s2">&quot;</span><span class="p">,</span>397        <span class="n">aTrueValue</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span>398        <span class="n">aFalseValue</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>399    <span class="p">),</span>400    <span class="n">someData</span> <span class="o">=</span> <span class="sa">b</span><span class="s2">&quot;&lt;binary gunk&gt;&quot;</span><span class="p">,</span>401    <span class="n">someMoreData</span> <span class="o">=</span> <span class="sa">b</span><span class="s2">&quot;&lt;lots of binary gunk&gt;&quot;</span> <span class="o">*</span> <span class="mi">10</span><span class="p">,</span>402    <span class="n">aDate</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>403<span class="p">)</span>404<span class="nb">print</span><span class="p">(</span><span class="n">plistlib</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">pl</span><span class="p">)</span><span class="o">.</span><span class="n">decode</span><span class="p">())</span>405</pre></div>406</div>407<p>Parsing a plist:</p>408<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">plistlib</span>409 410<span class="n">plist</span> <span class="o">=</span> <span class="sa">b</span><span class="s2">&quot;&quot;&quot;&lt;plist version=&quot;1.0&quot;&gt;</span>411<span class="s2">&lt;dict&gt;</span>412<span class="s2">    &lt;key&gt;foo&lt;/key&gt;</span>413<span class="s2">    &lt;string&gt;bar&lt;/string&gt;</span>414<span class="s2">&lt;/dict&gt;</span>415<span class="s2">&lt;/plist&gt;&quot;&quot;&quot;</span>416<span class="n">pl</span> <span class="o">=</span> <span class="n">plistlib</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">plist</span><span class="p">)</span>417<span class="nb">print</span><span class="p">(</span><span class="n">pl</span><span class="p">[</span><span class="s2">&quot;foo&quot;</span><span class="p">])</span>418</pre></div>419</div>420</section>421</section>422 423 424            <div class="clearer"></div>425          </div>426        </div>427      </div>428      <div class="sphinxsidebar" role="navigation" aria-label="Main">429        <div class="sphinxsidebarwrapper">430  <div>431    <h3><a href="../contents.html">Table of Contents</a></h3>432    <ul>433<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code> — Generate and parse Apple <code class="docutils literal notranslate"><span class="pre">.plist</span></code> files</a><ul>434<li><a class="reference internal" href="#examples">Examples</a></li>435</ul>436</li>437</ul>438 439  </div>440  <div>441    <h4>Previous topic</h4>442    <p class="topless"><a href="netrc.html"443                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">netrc</span></code> — netrc file processing</a></p>444  </div>445  <div>446    <h4>Next topic</h4>447    <p class="topless"><a href="crypto.html"448                          title="next chapter">Cryptographic Services</a></p>449  </div>450  <script>451    document.addEventListener('DOMContentLoaded', () => {452        const title = document.querySelector('meta[property="og:title"]').content;453        const elements = document.querySelectorAll('.improvepage');454        const pageurl = window.location.href.split('?')[0];455        elements.forEach(element => {456            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));457            url.searchParams.set('pagetitle', title);458            url.searchParams.set('pageurl', pageurl);459            url.searchParams.set('pagesource', "library/plistlib.rst");460            element.href = url.toString();461        });462    });463  </script>464  <div role="note" aria-label="source link">465    <h3>This page</h3>466    <ul class="this-page-menu">467      <li><a href="../bugs.html">Report a bug</a></li>468      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>469      <li>470        <a href="https://github.com/python/cpython/blob/main/Doc/library/plistlib.rst?plain=1"471            rel="nofollow">Show source472        </a>473      </li>474      475    </ul>476  </div>477        </div>478<div id="sidebarbutton" title="Collapse sidebar">479<span>«</span>480</div>481 482      </div>483      <div class="clearer"></div>484    </div>  485    <div class="related" role="navigation" aria-label="Related">486      <h3>Navigation</h3>487      <ul>488        <li class="right" style="margin-right: 10px">489          <a href="../genindex.html" title="General Index"490             >index</a></li>491        <li class="right" >492          <a href="../py-modindex.html" title="Python Module Index"493             >modules</a> |</li>494        <li class="right" >495          <a href="crypto.html" title="Cryptographic Services"496             >next</a> |</li>497        <li class="right" >498          <a href="netrc.html" title="netrc — netrc file processing"499             >previous</a> |</li>500 501          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>502          <li><a href="https://www.python.org/">Python</a> &#187;</li>503          <li class="switchers">504            <div class="language_switcher_placeholder"></div>505            <div class="version_switcher_placeholder"></div>506          </li>507          <li>508              509          </li>510    <li id="cpython-language-and-version">511      <a href="../index.html">3.15.0a6 Documentation</a> &#187;512    </li>513 514          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>515          <li class="nav-item nav-item-2"><a href="fileformats.html" >File Formats</a> &#187;</li>516        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code> — Generate and parse Apple <code class="docutils literal notranslate"><span class="pre">.plist</span></code> files</a></li>517                <li class="right">518                    519 520    <div class="inline-search" role="search">521        <form class="inline-search" action="../search.html" method="get">522          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">523          <input type="submit" value="Go">524        </form>525    </div>526                     |527                </li>528            <li class="right">529<label class="theme-selector-label">530    Theme531    <select class="theme-selector" oninput="activateTheme(this.value)">532        <option value="auto" selected>Auto</option>533        <option value="light">Light</option>534        <option value="dark">Dark</option>535    </select>536</label> |</li>537            538      </ul>539    </div>  540    <div class="footer">541    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.542    <br>543    This page is licensed under the Python Software Foundation License Version 2.544    <br>545    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.546    <br>547    548      See <a href="/license.html">History and License</a> for more information.<br>549    550    551    <br>552 553    The Python Software Foundation is a non-profit corporation.554<a href="https://www.python.org/psf/donations/">Please donate.</a>555<br>556    <br>557      Last updated on Mar 10, 2026 (08:58 UTC).558    559      <a href="/bugs.html">Found a bug</a>?560    561    <br>562 563    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.564    </div>565 566  </body>567</html>