Skip to main content

dotproperties

A zero-dependency, pure-Python reader and writer for Java Properties.

CI Codecov PyPI Python 3.10–3.14 Free-threaded CPython 3.14t License: MIT

dotproperties reads and writes the classic line-oriented java.util.Properties format.

It handles comments, continuations, separators, duplicate keys, Java escapes, and UTF-16 surrogate pairs. Byte and text input follow Java's distinct InputStream and Reader rules, and interoperability is checked against all current Eclipse Temurin LTS lines: 8, 11, 17, 21, and 25.

Install

Add dotproperties to a uv-managed project:

uv add dotproperties

Or install it with pip:

pip install dotproperties

Python 3.10 through 3.14 and free-threaded CPython 3.14t are supported. Python 3.15 and 3.15t previews are tested for forward compatibility until Python 3.15 is released.

Quick start

Parse a string with loads():

import dotproperties

config = dotproperties.loads(
    """
    # Application settings
    host = localhost
    port: 8080
    greeting = Olá
    """
)

print(config)
{'host': 'localhost', 'port': '8080', 'greeting': 'Olá'}

Serialize a mapping with dumps():

text = dotproperties.dumps(config)
print(text, end="")
host=localhost
port=8080
greeting=Ol\u00E1

Read and write files with load() and dump():

with open("application.properties", "rb") as fp:
    config = dotproperties.load(fp)

with open("application.properties", "w", encoding="ascii") as fp:
    dotproperties.dump(config, fp)

Encoding and streams

Strings and text streams are already-decoded character input, corresponding to Java's Properties.load(Reader). Bytes and binary streams use ISO-8859-1, matching Properties.load(InputStream).

Serialization produces text and escapes every non-ASCII code point by default, so the result is safe to write as ASCII and load through either Java path. Keys and values must be strings.

Set ensure_ascii=False to retain readable Unicode:

text = dotproperties.dumps({"greeting": "你好"}, ensure_ascii=False)

with open("application.properties", "w", encoding="utf-8") as fp:
    fp.write(text)

Load that file through a Java Reader using the same encoding. Passing its UTF-8 bytes to Properties.load(InputStream) would apply ISO-8859-1 instead.

load() makes bounded-size read requests. load() and dump() leave caller-owned streams open; dump() also leaves flushing to the caller and validates the complete mapping before its first write. A malformed \uXXXX escape raises ValueError.

dotproperties.__version__ reports the installed package version.

Format behavior

  • Leading spaces, tabs, and form feeds are ignored. # and ! begin comment lines after that leading whitespace; comment lines cannot be continued.
  • An odd run of trailing backslashes continues a logical line. Leading format whitespace on the next natural line is discarded.
  • The first unescaped =, :, space, tab, or form feed separates the key from the value. A missing value is the empty string.
  • \t, \n, \r, \f, and \uXXXX use Java's meanings. For other escaped characters, Java's rule drops the backslash.
  • Valid UTF-16 surrogate pairs become one Python Unicode character. Isolated surrogate units remain isolated and are always serialized as escapes.
  • Duplicate keys use the last value, matching Properties.load().

Parsing does not preserve comments or original spelling. Serialization emits only key=value lines: it does not add Java's timestamp comment. Entries follow the mapping's iteration order. Java 8 does not specify the order used by Properties.store(), while Java 25 sorts ordinary Properties by key. The format itself has no semantic order, so sort the mapping before serialization only when a particular textual order is required.

XML properties, defaults chains, interpolation, and lossless document editing are outside this package's scope.

Safety and resource limits

The line format is data-only. Parsing does not construct Python objects from type tags, evaluate expressions, expand variables, follow includes, or access external resources.

Like Properties.load(), dotproperties does not impose a document-size, logical-line, or entry-count limit. Bounded-size requests to fp.read() do not cap total CPU or memory use; the result and the longest unfinished logical line must still fit in memory. Applications accepting untrusted input should limit it before parsing.

dump() prevents invalid mapping entries from causing partial output, but an I/O failure can still interrupt a write. Applications that replace important files should write to a temporary file and perform an atomic replacement.

Development

The default development interpreter is Python 3.12. See CONTRIBUTING.md for setup, checks, interoperability testing, and releases. Report suspected vulnerabilities through the security policy. Participation is governed by the code of conduct.

License

dotproperties is available under the MIT License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dotproperties-0.1.0.tar.gz (42.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dotproperties-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file dotproperties-0.1.0.tar.gz.

File metadata

  • Download URL: dotproperties-0.1.0.tar.gz
  • Upload date:
  • Size: 42.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for dotproperties-0.1.0.tar.gz
Algorithm Hash digest
SHA256 543b0706f96aa9c4698b82733aff4d1950142d00458808e1f590771be0bc355c
MD5 5de0600ccae1c0d2d2cc91874248de6b
BLAKE2b-256 5d2c2300b28cdb682aeee73472519f878b0a6359706f0ab0d492a0472ea180a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for dotproperties-0.1.0.tar.gz:

Publisher: release.yml on cnzakii/dotproperties

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dotproperties-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dotproperties-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for dotproperties-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4b76bdb51aab039e2b949aaa88f18981d44ea775ae13ea649162dc14ba3c8d5
MD5 e022350fa3f7b952fc9169a5900fe9b8
BLAKE2b-256 236ea0422d6ae2ebd39e9a5da0b707c0ec6efa34ff36d9033a48a1404b4e2b7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for dotproperties-0.1.0-py3-none-any.whl:

Publisher: release.yml on cnzakii/dotproperties

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page