Skip to content

API Reference

regkit

Key

A key in the registry.

Usage style: - Use root factories (current_user, local_machine, ...) - Navigate with subkey(...) - Open with open(...) or create(...) in a context manager - Read/write values via dict-style access (key[name])

handle property

Returns the native backend handle for this open key.

Raises RuntimeError if the key is not open.

name property

Returns the final lexical path part for this key.

parent property

Returns the lexical parent key, or None for a registry root.

parts property

Returns path parts, including the root token when present.

__call__(*subkeys)

Compatibility shorthand for subkey(...).

__del__()

Destructor to ensure the key is closed

__delitem__(name)

Deletes a value from the key

__enter__()

Enter context manager. Raises RuntimeError if the key is not open

__getitem__(name)

Get a value from the key

__init__(parent, *names)

Create a new key object. The key is not opened or created.

__repr__()

Returns a string representation of the key

__setitem__(name, value)

Sets a value in the key. We assume a string

__str__()

Returns the full registry path for this key.

__truediv__(subkey)

Pathlib-style shorthand for subkey(...) with one path part.

as_dict(typed=False, include_name=False)

Returns the key and subkeys as a dictionary.

If typed is True, values are emitted under values_typed as a list of (name, value, type) tuples. Otherwise, values are emitted under values as a mapping from name to value.

If include_name is True, each node includes its lexical leaf name under name (informational only).

canonical_parts()

Returns canonical path parts for this key.

canonical_path()

Returns the canonical full registry path for this key.

classes_root(*subkeys) classmethod

Returns a key object for HKEY_CLASSES_ROOT

close()

Closes the key.

create(*subkeys)

Create helper.

Convenience helper that returns a new key opened for writing, creating it if necessary.

current_config(*subkeys) classmethod

Returns a key object for HKEY_CURRENT_CONFIG

current_user(*subkeys) classmethod

Returns a key object for HKEY_CURRENT_USER

delete(tree=False, missing_ok=True)

Deletes the key, optionally recursively.

dup()

Returns a new, un-opened copy of this key

exists()

checks if the key exists

from_dict(data, remove=False)

Sets the key and subkeys from a dictionary

from_parts(parts) classmethod

Creates a Key object from path parts.

The first item must be a registry root token (for example HKCU or HKEY_CURRENT_USER). Remaining items are subkey path components.

from_path(path) classmethod

Creates a Key object from a full registry path.

Examples: - HKEY_CURRENT_USER\Software\MyApp - HKCU\Software\MyApp

get(name, default=None)

Gets a value from the key

get_typed(name, default=None)

Gets a value from the key, returning (value, type).

Prefer dict-style access (key[name]) when the type is not needed.

is_hive()

Checks if the key is backed by a predefined registry hive handle.

is_open()

Checks if the key is opened

is_root()

Checks if the key is a root key

items()

Iterates over the values in the key, returning (name, value) typles

items_typed()

Iterates over the values in the key, returning (name, (value, type)) tuples.

iterdir()

Iterates over child subkeys (pathlib-style alias for subkeys).

joinpath(*subkeys)

Pathlib-style alias for subkey(...).

keys()

iterates of the item names in the key

local_machine(*subkeys) classmethod

Returns a key object for HKEY_LOCAL_MACHINE

open(*subkeys, create=False, write=False)

Open helper.

Returns a new opened Key object, leaving the original instance unchanged.

open_handle(create=False, write=False)

Opens this key in-place.

This is the low-level in-place open primitive used by open(...) and create(...).

If create is True, creates the key if it does not exist. If write is True, opens the key for writing. If 'create' is True, the key is always opened for writing. Raises KeyError if the key does not exist and 'create' is False.

parents()

Returns lexical ancestors from immediate parent up to root.

path()

Returns the full registry path for this key.

print(tree=False, indent=4, level=0)

Prints the key to stdout

set_typed(name, value, type=winreg.REG_SZ)

Sets a value in the key, with an explicit registry type.

Prefer dict-style assignment (key[name] = value) for common types.

subkey(*subkeys)

Navigation helper.

Returns a subkey object. If no subkeys are provided, it is the same as dup().

subkeys()

Iterates over the subkeys in the key

users(*subkeys) classmethod

Returns a key object for HKEY_USERS

values()

iterates of the item values in the key

values_typed()

iterates of the item values in the key, returning (value, type) tuples.

walk(topdown=True, onerror=None, max_depth=None)

Walks the key tree, yielding (key, subkey_names, value_names).

Semantics are similar to os.walk: - topdown=True yields a parent before children and allows pruning by mutating subkey_names in-place. - topdown=False yields children before parent.