### Install javaproperties Source: https://javaproperties.readthedocs.io Install the javaproperties library using pip. Requires Python 3.8 or higher. ```bash python3 -m pip install javaproperties ``` -------------------------------- ### Dump and load properties from file Source: https://javaproperties.readthedocs.io Writes properties to a file and reads them back using file-like objects. ```python >>> with open('example.properties', 'w', encoding='latin-1') as fp: ... javaproperties.dump(properties, fp) ... >>> with open('example.properties', 'r', encoding='latin-1') as fp: ... javaproperties.load(fp) ... {'goat': '🐐', 'host:port': '127.0.0.1:80', 'key': 'value', 'snowman': '☃'} ``` -------------------------------- ### Sort properties keys Source: https://javaproperties.readthedocs.io Outputs the properties with keys sorted alphabetically. ```python >>> print(javaproperties.dumps(properties, sort_keys=True)) #Mon Sep 26 14:57:44 EDT 2016 goat=\ud83d\udc10 host\:port=127.0.0.1\:80 key=value snowman=\u2603 ``` -------------------------------- ### Dump properties to string Source: https://javaproperties.readthedocs.io Converts a dictionary of properties into a Java properties formatted string. ```python >>> properties = {"key": "value", "host:port": "127.0.0.1:80", "snowman": "☃", "goat": "🐐"} >>> print(javaproperties.dumps(properties)) #Mon Sep 26 14:57:44 EDT 2016 key=value goat=\ud83d\udc10 host\:port=127.0.0.1\:80 snowman=\u2603 ``` -------------------------------- ### Dump properties as XML Source: https://javaproperties.readthedocs.io Serializes the properties dictionary into the Java XML properties format. ```python >>> print(javaproperties.dumps_xml(properties)) value 🐐 127.0.0.1:80 ``` -------------------------------- ### Line-Oriented .properties Functions Source: https://javaproperties.readthedocs.io High-level functions for reading and writing standard Java .properties files. ```APIDOC ## Line-Oriented .properties Functions ### Description Functions for serializing and deserializing simple line-oriented .properties files. ### Functions - **dump(props, fp)** - Writes properties to a file-like object. - **dumps(props)** - Returns properties as a string. - **load(fp)** - Reads properties from a file-like object. - **loads(s)** - Reads properties from a string. ``` -------------------------------- ### XML .properties Functions Source: https://javaproperties.readthedocs.io High-level functions for reading and writing XML-formatted Java .properties files. ```APIDOC ## XML .properties Functions ### Description Functions for serializing and deserializing XML-formatted .properties files. ### Functions - **dump_xml(props, fp)** - Writes properties to a file-like object in XML format. - **dumps_xml(props)** - Returns properties as an XML string. - **load_xml(fp)** - Reads properties from an XML file-like object. - **loads_xml(s)** - Reads properties from an XML string. ``` -------------------------------- ### Load properties from string Source: https://javaproperties.readthedocs.io Parses a Java properties formatted string into a Python dictionary. ```python >>> javaproperties.loads(''' ... #Mon Sep 26 14:57:44 EDT 2016 ... key = value ... goat: \\ud83d\\udc10 ... host\\:port=127.0.0.1:80 ... #foo = bar ... snowman ☃ ... ''') {'goat': '🐐', 'host:port': '127.0.0.1:80', 'key': 'value', 'snowman': '☃'} ``` -------------------------------- ### Dump Unicode without escaping Source: https://javaproperties.readthedocs.io Outputs Unicode characters directly instead of using escape sequences. ```python >>> print(javaproperties.dumps(properties, ensure_ascii=False)) #Tue Feb 25 19:13:27 EST 2020 key=value goat=🐐 host\:port=127.0.0.1\:80 snowman=☃ ``` -------------------------------- ### Set custom timestamp Source: https://javaproperties.readthedocs.io Uses a specific Unix timestamp for the properties header. ```python >>> print(javaproperties.dumps(properties, timestamp=1234567890)) #Fri Feb 13 18:31:30 EST 2009 key=value goat=\ud83d\udc10 host\:port=127.0.0.1\:80 snowman=\u2603 ``` -------------------------------- ### Disable timestamp in output Source: https://javaproperties.readthedocs.io Removes the timestamp header from the generated properties string. ```python >>> print(javaproperties.dumps(properties, timestamp=None)) key=value goat=\ud83d\udc10 host\:port=127.0.0.1\:80 snowman=\u2603 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.