{"id":2549,"library":"jproperties","title":"Java Property file parser and writer for Python","description":"jProperties is a Python library for parsing and writing Java `.properties` files. It aims to provide similar functionality to Java's `java.util.Properties` class, supporting key-value pairs, comments, and line continuations. Version 2.1.2 is the latest stable release. The project is actively maintained on GitHub with a focus on robust handling of Java-style property files.","status":"active","version":"2.1.2","language":"en","source_language":"en","source_url":"https://github.com/Tblue/python-jproperties","tags":["java","properties","configuration","parser","config-file"],"install":[{"cmd":"pip install jproperties","lang":"bash","label":"Install jproperties"}],"dependencies":[],"imports":[{"symbol":"Properties","correct":"from jproperties import Properties"}],"quickstart":{"code":"import os\nfrom jproperties import Properties\n\n# 1. Define a .properties file content\nprops_content = '''\\\n# My Application Configuration\napp.name=MyApp\napp.version=1.0.0\napp.env=development\n# _some_meta=value\ndb.host=localhost\ndb.port=5432\n'''\n\n# 2. Write it to a temporary file\nprop_file_path = \"config.properties\"\nwith open(prop_file_path, \"wb\") as f:\n    # jproperties expects bytes, often iso-8859-1 for Java properties\n    f.write(props_content.encode('iso-8859-1'))\n\n# 3. Load the properties\np = Properties()\nwith open(prop_file_path, \"rb\") as f:\n    p.load(f, \"iso-8859-1\") # Specify encoding, defaults to iso-8859-1\n\n# 4. Access values\napp_name, app_name_meta = p[\"app.name\"]\nprint(f\"App Name: {app_name} (Metadata: {app_name_meta})\")\n\ndb_host, db_host_meta = p[\"db.host\"]\nprint(f\"DB Host: {db_host} (Metadata: {db_host_meta})\")\n\n# 5. Modify / Add properties (with metadata)\np[\"app.version\"] = \"1.1.0\", {\"last_updated\": \"2026-04-10\"}\np[\"new.setting\"] = \"some_value\"\n\n# 6. Store properties to a new file (including metadata)\nout_prop_file_path = \"config_updated.properties\"\nwith open(out_prop_file_path, \"wb\") as f:\n    p.store(f, \"Updated Configuration\", timestamp=False, strip_meta=False)\n\nprint(f\"\\nUpdated configuration written to: {out_prop_file_path}\")\n\n# Clean up temporary files\nos.remove(prop_file_path)\nos.remove(out_prop_file_path)\n","lang":"python","description":"This quickstart demonstrates how to create a `.properties` file, load its contents into a `jproperties.Properties` object, access property values (including their associated metadata), modify and add new properties, and then store the updated properties back to a file. It highlights the use of `iso-8859-1` encoding, which is common for Java properties files."},"warnings":[{"fix":"Upgrade to Python 3.8 or newer, or pin `jproperties<2.1.3` for Python 2.7 compatibility.","message":"Version 2.1.2 is the last version to support Python 2.7. Subsequent versions (post 2.1.2) drop support for Python versions older than 3.8. Ensure your Python environment meets the required version for the specific `jproperties` release you are using.","severity":"breaking","affected_versions":">=2.1.3 (implicitly, based on changelog stating post-2.1.2 drops support)"},{"fix":"When calling `p.store(file_obj, comments, strip_meta=False)`, ensure `strip_meta=False` is passed if metadata persistence is desired.","message":"The `store()` method, by default, does not write out metadata associated with properties. To include metadata in the output file, you must explicitly set `strip_meta=False` when calling `store()`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `del prop_obj[key]` to delete a property and its metadata, or `prop_obj[key] = value` or `prop_obj[key] = value, metadata` to set values with or without updating metadata.","message":"Directly modifying or deleting key-value pairs via the internal `prop_obj.properties` dictionary (e.g., `del prop_obj.properties[key]`) will NOT remove any associated metadata. To ensure metadata is also removed, always use the dictionary-like access on the `Properties` object itself (e.g., `del prop_obj[key]`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use the plain text `.properties` format or choose a different library (e.g., `javaproperties`) if XML format is required.","message":"The `jproperties` library does not support the XML property file format used by Java's `Properties` class. It specifically targets the plain text `.properties` file format. If you need XML support, consider alternative libraries like `javaproperties`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `value, metadata = p[key]` for paired access or `p.getmeta(key)` to retrieve metadata explicitly.","message":"When iterating over a `Properties` object (e.g., `for key in p:`), only the keys are returned. Associated metadata is not included. To retrieve metadata for a specific key, you must access it using `value, metadata = p[key]` or `p.getmeta(key)`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}