{"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":"python","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,"search_vec":"'2.1.2':42 'activ':51 'aim':22 'class':31 'comment':37 'config':72 'config-fil':71 'configur':69 'continu':40 'file':3,20,66,73 'focus':57 'function':26 'github':54 'handl':60 'java':1,18,28,63,67 'java-styl':62 'java.util.properties':30 'jproperti':9 'key':34 'key-valu':33 'latest':45 'librari':13 'line':39 'maintain':52 'pair':36 'pars':15 'parser':4,70 'project':49 'properti':2,19,65,68 'provid':24 'python':8,12 'releas':47 'robust':59 'similar':25 'stabl':46 'style':64 'support':32 'valu':35 'version':41 'write':17 'writer':6","created_at":"2026-04-11T01:32:48.054164+00:00","updated_at":"2026-04-16T15:53:36.208722+00:00","problems":[{"fix":"Install the library using pip: `pip install jproperties`","cause":"The 'jproperties' library is not installed in your Python environment.","error":"ModuleNotFoundError: No module named 'jproperties'"},{"fix":"Open the .properties file in binary read mode ('rb') when loading it: `with open('your.properties', 'rb') as f: p.load(f)`","cause":"This error typically occurs when trying to load a properties file opened in text mode ('rt') with the 'jproperties' load method, which expects a file-like object opened in binary mode ('rb') because it handles byte streams for encoding/decoding.","error":"TypeError: can't concat str to bytes"},{"fix":"Review the specified line number in your .properties file to correct any syntax errors (e.g., unescaped special characters, malformed key-value pairs, incorrect line continuations). Ensure the file adheres to the Java .properties file format.","cause":"The .properties file contains invalid syntax or an unexpected format that 'jproperties' cannot parse according to the Java .properties file specification.","error":"jproperties.ParseError: Parse error in <filename>:<line_number>: <error_message>"},{"fix":"Ensure the key exists in the properties file and is correctly spelled. You can check for a key's existence using `if 'your_key' in p:` or use the `get()` method with a default value: `value = p.get('your_key', 'default_value')`.","cause":"You are attempting to access a property using a key that does not exist in the loaded 'Properties' object.","error":"KeyError: '<key_name>'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.1.2","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/Tblue/python-jproperties","docs":null,"changelog":null,"pypi":"https://pypi.org/project/jproperties/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}