{"id":1841,"library":"javaproperties","title":"javaproperties","description":"javaproperties is a Python library that provides comprehensive support for reading and writing Java `.properties` files, encompassing both the simple line-oriented format and XML. It offers a straightforward API inspired by Python's `json` module, alongside a `Properties` class designed to emulate the behavior of Java 8's `java.util.Properties` as closely as possible in Python. The library is actively maintained, with the latest version 0.8.2 released in December 2024, and its release cadence is irregular, with significant gaps between major versions.","status":"active","version":"0.8.2","language":"en","source_language":"en","source_url":"https://github.com/jwodder/javaproperties","tags":["java","properties","config","configuration","file format"],"install":[{"cmd":"pip install javaproperties","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Requires Python 3.10 or higher as of version 0.8.2.","package":"python","optional":false}],"imports":[{"note":"Function to serialize a Python dict to a .properties string.","symbol":"dumps","correct":"from javaproperties import dumps"},{"note":"Function to deserialize a .properties string to a Python dict.","symbol":"loads","correct":"from javaproperties import loads"},{"note":"Function to serialize a Python dict to a file-like object.","symbol":"dump","correct":"from javaproperties import dump"},{"note":"Function to deserialize a file-like object to a Python dict.","symbol":"load","correct":"from javaproperties import load"},{"note":"Class mimicking Java's java.util.Properties, providing dictionary-like interface with additional methods.","symbol":"Properties","correct":"from javaproperties import Properties"}],"quickstart":{"code":"import javaproperties\nimport io\n\n# Example data to work with\ndata = {\n    \"key\": \"value\",\n    \"host:port\": \"127.0.0.1:80\",\n    \"snowman\": \"☃\",\n    \"goat\": \"🐐\",\n    \"multiline_value\": \"line1\\\\nline2\"\n}\n\n# 1. Serialize a Python dictionary to a .properties string\nprint(\"--- DUMPING TO STRING ---\")\nproperties_string = javaproperties.dumps(data, sort_keys=True, timestamp=None)\nprint(properties_string)\n\n# 2. Deserialize a .properties string back to a Python dictionary\nprint(\"\\n--- LOADING FROM STRING ---\")\nloaded_data_string = javaproperties.loads(properties_string)\nprint(loaded_data_string)\n\n# 3. Serialize to a file-like object (using StringIO for demonstration)\nprint(\"\\n--- DUMPING TO/LOADING FROM FILE ---\")\nwith io.StringIO() as fp:\n    javaproperties.dump(data, fp, sort_keys=True, timestamp=None, encoding='latin-1')\n    fp.seek(0) # Rewind to beginning to read\n    file_content = fp.read()\n    print(\"File content:\\n\", file_content)\n\n    fp.seek(0) # Rewind again for loading\n    loaded_data_file = javaproperties.load(fp, encoding='latin-1')\n    print(\"Loaded from file:\", loaded_data_file)\n\n# 4. Using the Properties class (Java-like interface)\nprint(\"\\n--- USING PROPERTIES CLASS ---\")\nprops = javaproperties.Properties()\nprops.update(data)\nprint(f\"Properties object (dict-like): {props}\")\nprint(f\"Value for 'snowman': {props.get('snowman')}\")\n\n# Storing to a file with Properties class\nwith io.StringIO() as fp_props:\n    props.store(fp_props, timestamp=None, encoding='latin-1')\n    fp_props.seek(0)\n    print(\"Properties class output:\\n\", fp_props.read())\n","lang":"python","description":"This quickstart demonstrates how to use `javaproperties` to serialize Python dictionaries to Java `.properties` strings and files, and deserialize them back. It also shows the usage of the `Properties` class, which offers an API similar to Java's `java.util.Properties`."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or newer. Check the PyPI page for the exact `Requires-Python` metadata if using older `javaproperties` versions.","message":"Version 0.8.0 dropped support for Python 2.7, 3.4, and 3.5. Users on these Python versions must upgrade to Python 3.8+ (or 3.10+ for 0.8.2).","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"Update code to iterate over the `PropertiesElement` objects returned by `parse()` and access their attributes (e.g., `element.key`, `element.value`, `element.source`).","message":"In version 0.7.0, the `javaproperties.parse()` function's return type changed from triples of strings to a generator of custom `PropertiesElement` objects. Code relying on the old return structure will break.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Ensure that any input `.properties` files are correctly formatted, especially concerning Unicode escape sequences. Implement error handling for `InvalidUEscapeError` if processing untrusted input.","message":"As of version 0.5.0, parsing invalid `\\uXXXX` escape sequences will now raise an `InvalidUEscapeError` instead of potentially silently failing or producing incorrect output.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"If you relied on the CLI tools, you need to install the `javaproperties-cli` package separately: `pip install javaproperties-cli`.","message":"The command-line interface (CLI) tools (e.g., `javaproperties`, `json2properties`, `properties2json`) were split into a separate `javaproperties-cli` package as of version 0.4.0.","severity":"gotcha","affected_versions":">=0.4.0"},{"fix":"Ensure all keys and values passed to `Properties` or `PropertiesFile` instances are strings. Utilize static type checkers (like MyPy) in your development workflow to catch type mismatches proactively.","message":"Starting with version 0.8.0, the `Properties` and `PropertiesFile` classes no longer explicitly raise `TypeError` when given non-string keys or values. The library now relies on static type checking to enforce type correctness.","severity":"gotcha","affected_versions":">=0.8.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}