Skip to main content

WinRegistry

PyPI PyPI

A Python library for interacting with the Windows registry.

Windows only. This library depends on the standard library module winreg, which is available only on Windows. On Linux or macOS you will get ModuleNotFoundError: No module named 'winreg'; use Windows or guard usage with a platform check (e.g. if sys.platform == "win32"). This library provides a simple and intuitive API for performing common registry operations, making it easier to work with the Windows registry in Python applications and automated tests.

Installation

Install via PyPI:

pip install winregistry

Usage

Creating and Deleting Registry Keys

import winreg
from winregistry import open_key

# Create a registry key
with open_key(
  "HKLM\\SOFTWARE\\MyApp",
  sub_key_ensure=True,
  sub_key_access=winreg.KEY_WRITE,
) as key:
  print("Registry key created")

# Delete a registry key
with open_key(
  "HKLM\\SOFTWARE",
  sub_key_access=winreg.KEY_WRITE,
) as key:
  key.delete_key("MyApp")
  print("Registry key deleted")

Setting and Reading Registry Values

import winreg
from winregistry import open_key, open_value

# Set a registry value
with open_key(
  "HKLM\\SOFTWARE\\MyApp",
  sub_key_ensure=True,
  sub_key_access=winreg.KEY_WRITE,
) as key:
  key.set_value(
    "MyValue",
    winreg.REG_SZ,
    "Sample Data",
  )
  print("Registry value set")

# Read a registry value
with open_value(
  "HKLM\\SOFTWARE\\MyApp",
  value_name="MyValue",
) as value:
  print(f"Registry value: {value.data}")

Enumerating Subkeys and Values

import winreg
from winregistry import open_key

# Enumerate subkeys
with open_key(
  "HKLM\\SOFTWARE",
  sub_key_access=winreg.KEY_READ,
) as key:
  subkeys = list(key.child_keys_names)
  print(f"Subkeys: {subkeys}")

# Enumerate values
with open_key(
  "HKLM\\SOFTWARE\\MyApp",
  sub_key_access=winreg.KEY_READ,
) as key:
  values = [(v.name, v.data) for v in key.values]
  print(f"Values: {values}")

Usage with Robot Testing Framework

The library provides a Robot Framework library that makes it easy to work with the Windows registry in automated tests. The library is available as winregistry.robot.

Documentation

For detailed documentation of the Robot Framework library, visit:

https://shpaker.github.io/winregistry/winregistry.robot.html

Example Tests

A complete set of example tests demonstrating various registry operations can be found in the winregistry_tests.robot file. These tests cover:

  • Creating and deleting registry keys
  • Working with nested registry keys
  • Setting and reading registry values
  • Verifying registry key and value existence
  • Enumerating subkeys and values

Contributing

Contributions are welcome!

Commit messages follow the Conventional Commits specification.

Setting Up the Development Environment

We use uv for dependency management and packaging. To set up your development environment, follow these steps:

  1. Install uv if you haven't already:

    pip install uv
    
  2. Install the project dependencies:

    uv sync --group dev
    

Code Formatting and Linting

We use ruff for code formatting and linting. The following tasks are defined in the Justfile to help with these processes:

  • Format the code:

    just fmt
    
  • Run the linter:

    just lint
    

License

This project is licensed under the MIT License.

Release files for winregistry 2.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for winregistry 2.1.5
File Size Uploaded
winregistry-2.1.5.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for winregistry 2.1.5
File Interpreter ABI Platform
winregistry-2.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 18.8 kB

Release files / winregistry-2.1.5.tar.gz

Download URL winregistry-2.1.5.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
05525ecac026dbdd2d20428a532354138dc6711de8a8f8efdc40484131627ba8
BLAKE2b-256 checksum
How to use checksums
58b457c8cd9c3a50b0b71ab924377a12326c528f822c35cc60d192dec423e3b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","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}

Release files / winregistry-2.1.5-py3-none-any.whl

Download URL winregistry-2.1.5-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
84e597b8f06c985a6be397e8c75400c2d72797d24134eb740b7b2f3de13089c1
BLAKE2b-256 checksum
How to use checksums
699b5e05038bfe8e2109b83bfd7237668d5cd26f038380ed9cf4db4b441966d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","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}
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page