A modern, pythonic interface to the Windows registry.
Project description
regkit
A modern, pythonic interface to the Windows registry.
Introduction
Python comes with winreg for registry operations, but it is a thin wrapper over
Win32 APIs and can be cumbersome for day-to-day usage.
regkit provides a higher-level, object-oriented interface with simple tree
navigation, dict-like value access, and context-manager support.
Features
- Easy-to-use API for reading and writing Windows Registry keys
- Python 3.11+
- Windows platform
- MIT License
- Managed and built with uv
Installation
pip install regkit
Or the equivalent command in your preferred package manager.
Usage
Library
from regkit import current_user
import winreg
# open for read
with current_user.subkey("Software", "MyApp").open() as key:
print(key["name"])
print(key.get("missing", "default"))
# open for write (subkeys can be passed directly to open as a convenience)
with current_user.open("Software", "MyApp", write=True) as key:
key["name"] = "regkit"
key["enabled"] = 1
# pathlib-style path concatenation is also supported via "/"
with (current_user / "Software" / "MyApp").open(write=True) as key:
key["theme"] = "dark"
# create/open for write (create is shorthand for open(create=True, write=True))
with current_user.create("Software", "MyApp") as key:
key["name"] = "regkit"
key["enabled"] = 1
# the Key object provides dict access and values can be iterated over:
with current_user.open("Software", "MyApp") as key:
for name, value in key.items():
print(name, value)
# the underlying type of a value can be retrieved, and a custom type can be
# set, overriding default conversions:
with current_user.open("Software", "MyApp", write=True) as key:
value, value_type = key.get_typed("enabled")
print(value, value_type)
key.set_typed("payload", b"\x00\x01\x02", winreg.REG_BINARY)
# existence checks are available on keys:
app_key = current_user.subkey("Software", "MyApp")
print(app_key.exists())
subkey(...) is optional convenience for pre-building a path. You can either
chain with subkey(...) first, or pass subkeys directly to open(...) / create(...).
Typical workflow
- Use root factories (
current_user,local_machine, etc.) - Navigate with
subkey(...)(optional) - Open with
open(...)orcreate(...)and a context manager - Use dict-style value access (
key[name],key[name] = value) - Use
get_typed/set_typedonly when explicit registry types are needed
Using registry paths
Key supports constructing and round-tripping full registry paths.
from regkit import Key
# Construct from explicit path parts
key = Key.from_parts(("HKCU", "Software", "MyApp"))
# Construct from a full path string (either HKCU or HKEY_CURRENT_USER style)
same_key = Key.from_path(r"HKEY_CURRENT_USER\Software\MyApp")
# Read parts back (root token + subkey parts)
assert key.parts == ("HKCU", "Software", "MyApp")
# name is the final lexical segment
assert key.name == "MyApp"
# parents() returns lexical ancestors from nearest parent upward
assert [ancestor.name for ancestor in key.parents()] == ["Software", "HKCU"]
Use from_parts(...) when you already have tokenized components, and
from_path(...) when parsing user-provided registry path strings.
Key methods at a glance
subkey(*parts): build a child key path without opening itopen(...): return a new opened key for read/write accesscreate(*parts): shorthand for creating/opening a key for writingexists(): check whether a key existswalk(...): traverse a key tree, yielding(key, subkey_names, value_names)(similar toos.walk())keys(),values(),items(): iterate value names, values, or(name, value)pairsname: final lexical path segment for this keyparts: tuple of key path components, including root token when presentparent: lexical parent key (orNoneat registry root)parents(): tuple of lexical ancestors from immediate parent up to rootget(name, ...): read a value with fallback defaultget_typed(...)/set_typed(...): read/write values with explicit registry typevalue_del(name)ordel key[name]: delete a valuedelete(...): delete a key (optionally recursively)as_dict()/from_dict(data): export/import a subtree structure
Default value name
The registry's default (unnamed) value is represented by the empty string ("").
- Iteration methods (
items(),items_typed(),keys()) return""for the default value name. - Set/delete helpers also accept
Noneas an equivalent.
Development
This project uses the uv package manager.
-
Install uv, e.g. using
pip install uv -
Install dev dependencies:
uv sync --dev
-
Run tests:
uv run pytest
-
Build docs:
uv sync --group docs uv run mkdocs build --strict
License
MIT License. See LICENSE for details.
Changelog
See CHANGELOG.md for release history and policy.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file regkit-0.3.0.tar.gz.
File metadata
- Download URL: regkit-0.3.0.tar.gz
- Upload date:
- Size: 66.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee46aca415b9b23ae7954d76771f14f553e07a86d520862d89adb9cae961a33c
|
|
| MD5 |
c8a45c995be4000120e1d8058b365e94
|
|
| BLAKE2b-256 |
d3aa6cb8bfda8f9cb1bb2f0ae9ae096d8b62ff9614eed6289be0f53f31746bad
|
File details
Details for the file regkit-0.3.0-py3-none-any.whl.
File metadata
- Download URL: regkit-0.3.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b21218bf3047fd43e45f27769cd9c8940a7d7a4121aac3fa2456c2bad0dce67
|
|
| MD5 |
21a8170f5ea7b2f43c9b7e2adc7fcb40
|
|
| BLAKE2b-256 |
525aff7eb45fba9fda348cc448cbf20be47f72cc835f50bedb11c794f71ec83f
|