Library aimed at working with Windows registry
Project description
from winregistry import create_key
WinRegistry
Python package aimed at working with Windows Registry
Installation
Install via PyPI:
pip install winregistry
QuickStart
import winreg
import winregistry
KEY_NAME_FOR_TESTING = 'HKLM\SOFTWARE\_REMOVE_ME_'
# create key
winregistry.create_key(KEY_NAME_FOR_TESTING)
winregistry.create_key(f'{KEY_NAME_FOR_TESTING}\some_subkey')
print(list(winregistry.child_keys_names(f'{KEY_NAME_FOR_TESTING}\_REMOVE_ME_')))
# manipulations with values
winregistry.values_names(KEY_NAME_FOR_TESTING)
winregistry.set_value(KEY_NAME_FOR_TESTING, 'smth', winreg.REG_SZ, 'some data')
winregistry.values_names(KEY_NAME_FOR_TESTING)
with winregistry.read_value(KEY_NAME_FOR_TESTING, 'smth') as value:
value.data = 'updated data!'
print(winregistry.read_value_data(KEY_NAME_FOR_TESTING, 'smth'))
winregistry.delete_value(KEY_NAME_FOR_TESTING, 'smth')
# delete key
winregistry.delete_key(f'{KEY_NAME_FOR_TESTING}\some_subkey')
winregistry.delete_key(KEY_NAME_FOR_TESTING)
Advances usage
import winreg
from winregistry import open_key
# connect to registry
with open_key(
winreg.HKEY_LOCAL_MACHINE,
) as hklm:
...
# connect to registry and open sub-key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE",
) as key:
...
# connect to registry and ensure sub-key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE\_REMOVE_ME_",
sub_key_ensure=True,
) as key:
...
# also you can connect to registry with string key
with open_key(
"HKLM\SOFTWARE",
) as key:
...
# open key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
) as hklm:
with hklm.open_key("SOFTWARE"):
...
# create or open sub-key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE",
) as key:
with key.create_key("_REMOVE_ME_"):
...
# delete key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE",
) as key:
key.delete_key("_REMOVE_ME_")
# set value to subkey
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE\_REMOVE_ME_",
sub_key_ensure=True,
) as key:
key.set_value(
name="remove_me",
type=winreg.REG_SZ,
value="Remove me!",
)
# read value
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE\_REMOVE_ME_",
sub_key_ensure=True,
) as key:
value = key.read_value("remove_me")
# change data of value
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE\_REMOVE_ME_",
sub_key_ensure=True,
) as key:
value.data = "Don't forget remove me!"
# delete value in subkey
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE\_REMOVE_ME_",
sub_key_ensure=True,
) as key:
value = key.delete_value("remove_me")
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
winregistry-2.0.0a3.tar.gz
(5.5 kB
view details)
Built Distribution
File details
Details for the file winregistry-2.0.0a3.tar.gz
.
File metadata
- Download URL: winregistry-2.0.0a3.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.15 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9257aba5610b585a9e00854b71b8080280d0266d1874f9ce79e67240a5500458 |
|
MD5 | ddb2669186b486713538de172a0e1cf0 |
|
BLAKE2b-256 | 0542a6a32b5b762adbead3f7d70541a5448dca9d70a853724e426278223dccb6 |
File details
Details for the file winregistry-2.0.0a3-py3-none-any.whl
.
File metadata
- Download URL: winregistry-2.0.0a3-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.15 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2def664bb2b7bd99af190d1dcc882668a674a444c604e9a35f85cfb39c2bfd4b |
|
MD5 | 95a9c8f1238744f45e97bdaad8ab38b8 |
|
BLAKE2b-256 | 9aa88dc85f87903524e8ddb7cf725892a39213c2560bfb9eae61775af931ecf7 |