GitHub | PyPI | Documentation | Issues | Changelog
javaproperties provides support for reading & writing Java .properties files (both the simple line-oriented format and XML) with a simple API based on the json module — though, for recovering Java addicts, it also includes a Properties class intended to match the behavior of Java 8’s java.util.Properties as much as is Pythonically possible.
Previous versions of javaproperties included command-line programs for basic manipulation of .properties files. As of version 0.4.0, these programs have been split off into a separate package, javaproperties-cli.
Installation
javaproperties requires Python 3.8 or higher. Just use pip for Python 3 (You have pip, right?) to install it:
python3 -m pip install javaproperties
Examples
Dump some keys & values (output order not guaranteed):
>>> 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
Load some keys & values:
>>> 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 some properties to a file and read them back in again:
>>> 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 the properties you’re dumping:
>>> 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
Turn off the timestamp:
>>> print(javaproperties.dumps(properties, timestamp=None)) key=value goat=\ud83d\udc10 host\:port=127.0.0.1\:80 snowman=\u2603
Use your own timestamp (automatically converted to local time):
>>> 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
Dump as XML:
>>> print(javaproperties.dumps_xml(properties)) <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <entry key="key">value</entry> <entry key="goat">🐐</entry> <entry key="host:port">127.0.0.1:80</entry> <entry key="snowman">☃</entry> </properties>
New in v0.6.0: Dump Unicode characters as-is instead of escaping them:
>>> 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=☃
Metadata
Release files for javaproperties 0.8.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| javaproperties-0.8.2.tar.gz | 40.6 kB | Without provenance | Details for javaproperties-0.8.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| javaproperties-0.8.2-py3-none-any.whl | Python 3 | none | any | Details for javaproperties-0.8.2-py3-none-any.whl |
Total release size: 64.3 kB
Release files / javaproperties-0.8.2.tar.gz
| Download URL | javaproperties-0.8.2.tar.gz |
|---|---|
| Size | 40.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f780d17ca12d57da58519dcf9d821cbcdb6f98a8b5af661013e31a5050c59a0f
|
|
BLAKE2b-256 checksum How to use checksums |
62b6366850e576cc9052b0f5ace2b554d061be9370d95c08b69d0de7212591b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.13.0
|
Release files / javaproperties-0.8.2-py3-none-any.whl
| Download URL | javaproperties-0.8.2-py3-none-any.whl |
|---|---|
| Size | 23.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
30141f83c45b574e204ee8170071535815994f468726813ec90f2d7f9fa6e7c1
|
|
BLAKE2b-256 checksum How to use checksums |
fdbecf9d60226f19072d6033dd2696782446272c147f4527c1906ae99b784dcc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.13.0
|
Security for javaproperties 0.8.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.