A Python library for interacting with the Windows registry
Project description
WinRegistry
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:
-
Install
uvif you haven't already:pip install uv
-
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.
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 winregistry-2.1.4.tar.gz.
File metadata
- Download URL: winregistry-2.1.4.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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 |
c557e6ec26a2827625451bbcee394b2d4c1fbccb6d7dca066335f397c0be1f89
|
|
| MD5 |
b6fe91017aea64c2f58b10c2b6f33ad1
|
|
| BLAKE2b-256 |
46ab6c646e9b2b6bd30c10fa69bf6733cc6eb519611552f0915c18e1522ac743
|
File details
Details for the file winregistry-2.1.4-py3-none-any.whl.
File metadata
- Download URL: winregistry-2.1.4-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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 |
8a2ead541bf9737d2cf4aa7c36363054a792a9f5c8fdaf0f7e3739ff9ddb092f
|
|
| MD5 |
e43dc4e78bfc2bdebcfd20ec0f18970b
|
|
| BLAKE2b-256 |
e873de41b09e8988451f7911ee31c39ba0fc6430ba60667110006b324e96a50b
|