# WinRegistry
[![PyPI](https://img.shields.io/pypi/v/winregistry.svg)](https://pypi.python.org/pypi/winregistry)
[![PyPI](https://img.shields.io/pypi/dm/winregistry.svg)](https://pypi.python.org/pypi/winregistry)
A Python library for interacting with the Windows registry
## Features
- Easy to use API for Windows registry operations
- Supports creating, reading, updating, and deleting registry keys and values
- Compatible with Robot Framework for automated testing
## Installation
Install via PyPI:
```bash
pip install winregistry
```
## Usage
### Creating and Deleting Registry Keys
```python
import winreg
from winregistry import open_key
# Create a registry key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="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(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE",
sub_key_access=winreg.KEY_WRITE
) as key:
key.delete_key("MyApp")
print("Registry key deleted")
```
### Setting and Reading Registry Values
```python
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_SET_VALUE
) as key:
key.set_value("MyValue", "Sample Data", winreg.REG_SZ)
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
```python
from winregistry import open_key
# Enumerate subkeys
with open_key(
"HKLM\\SOFTWARE",
sub_key_access=winreg.KEY_READ
) as key:
subkeys = key.enum_subkeys()
print(f"Subkeys: {subkeys}")
# Enumerate values
with open_key(
"HKLM\\SOFTWARE\\MyApp",
sub_key_access=winreg.KEY_READ
) as key:
values = key.enum_values()
print(f"Values: {values}")
```
## Usage with [Robot Testing Framework](https://robotframework.org/)
### Documentation
https://shpaker.github.io/winregistry/winregistry.robot
### Example
```robotframework
*** Variables ***
${ SUITE_KEY_NAME } HKLM\\SOFTWARE\\_ROBOT_TESTS_
${ SHORT_CASE_KEY_NAME } _CASE_KEY_
${ CASE_KEY_NAME } ${ SUITE_KEY_NAME }\\${ SHORT_CASE_KEY_NAME }
${ VALUE_NAME } some_testing_value
*** Settings ***
Library Collections
Library winregistry.robot
Suite Setup Create Registry Key ${ SUITE_KEY_NAME }
Suite Teardown Delete Registry Key ${ SUITE_KEY_NAME }
*** Test Cases ***
TEST REGISTRY KEYS
[Teardown] Delete Registry Key ${ CASE_KEY_NAME }
${ items } = Get Registry Key Sub Keys ${ SUITE_KEY_NAME }
List Should Not Contain Value ${ items } ${ SHORT_CASE_KEY_NAME }
Registry Key Should Not Exist ${ CASE_KEY_NAME }
Create Registry Key ${ CASE_KEY_NAME }
Registry Key Should Exist ${ CASE_KEY_NAME }
${ items } = Get Registry Key Sub Keys ${ SUITE_KEY_NAME }
List Should Contain Value ${ items } ${ SHORT_CASE_KEY_NAME }
TEST REGISTRY VALUES
[Setup] Create Registry Key ${ CASE_KEY_NAME }
[Teardown] Delete Registry Key ${ CASE_KEY_NAME }
${ items } = Get Registry Key Values Names ${ CASE_KEY_NAME }
List Should Not Contain Value ${ items } ${ VALUE_NAME }
Registry Value Should Not Exist ${ CASE_KEY_NAME } ${ VALUE_NAME }
Create Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME } SZ
Registry Value Should Exist ${ CASE_KEY_NAME } ${ VALUE_NAME }
${ items } = Get Registry Key Values Names ${ CASE_KEY_NAME }
List Should Contain Value ${ items } ${ VALUE_NAME }
${ value } = Read Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME }
Should Be Equal ${ value.data } ${ EMPTY }
Set Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME } Remove me!
${ value } = Read Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME }
Should Be Equal ${ value.data } Remove me!
Delete Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME }
```
## Contributing
Contributions are welcome! Please read our contributing guidelines for more details.
### Setting Up the Development Environment
We use `poetry` for dependency management and packaging. To set up your development environment, follow these steps:
1. Install `poetry` if you haven't already:
```bash
pip install poetry
```
2. Install the project dependencies:
```bash
poetry install --sync
```
### 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:**
```bash
just fmt
```
- **Run the linter:**
```bash
just lint
```
## License
This project is licensed under the MIT License.
Raw data
{
"_id": null,
"home_page": "https://github.com/shpaker/winregistry",
"name": "winregistry",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "windows, registry, regedit, winreg",
"author": "Aleksandr Shpak",
"author_email": "shpaker@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/c5/61/e7f3cd5df9ef559545fb36e1ecef8e89d64381de522fd3106c10e7e42bcf/winregistry-2.1.0.tar.gz",
"platform": null,
"description": "# WinRegistry\n\n[![PyPI](https://img.shields.io/pypi/v/winregistry.svg)](https://pypi.python.org/pypi/winregistry)\n[![PyPI](https://img.shields.io/pypi/dm/winregistry.svg)](https://pypi.python.org/pypi/winregistry)\n\nA Python library for interacting with the Windows registry\n\n## Features\n\n- Easy to use API for Windows registry operations\n- Supports creating, reading, updating, and deleting registry keys and values\n- Compatible with Robot Framework for automated testing\n\n## Installation\n\nInstall via PyPI:\n\n```bash\npip install winregistry\n```\n\n## Usage\n\n### Creating and Deleting Registry Keys\n\n```python\nimport winreg\nfrom winregistry import open_key\n\n# Create a registry key\nwith open_key(\n winreg.HKEY_LOCAL_MACHINE,\n sub_key=\"SOFTWARE\\\\MyApp\",\n sub_key_ensure=True,\n sub_key_access=winreg.KEY_WRITE\n) as key:\n print(\"Registry key created\")\n\n# Delete a registry key\nwith open_key(\n winreg.HKEY_LOCAL_MACHINE,\n sub_key=\"SOFTWARE\",\n sub_key_access=winreg.KEY_WRITE\n) as key:\n key.delete_key(\"MyApp\")\n print(\"Registry key deleted\")\n```\n\n### Setting and Reading Registry Values\n\n```python\nfrom winregistry import open_key, open_value\n\n# Set a registry value\nwith open_key(\n \"HKLM\\\\SOFTWARE\\\\MyApp\",\n sub_key_ensure=True,\n sub_key_access=winreg.KEY_SET_VALUE\n) as key:\n key.set_value(\"MyValue\", \"Sample Data\", winreg.REG_SZ)\n print(\"Registry value set\")\n\n# Read a registry value\nwith open_value(\n \"HKLM\\\\SOFTWARE\\\\MyApp\",\n value_name=\"MyValue\"\n) as value:\n print(f\"Registry value: {value.data}\")\n```\n\n### Enumerating Subkeys and Values\n\n```python\nfrom winregistry import open_key\n\n# Enumerate subkeys\nwith open_key(\n \"HKLM\\\\SOFTWARE\",\n sub_key_access=winreg.KEY_READ\n) as key:\n subkeys = key.enum_subkeys()\n print(f\"Subkeys: {subkeys}\")\n\n# Enumerate values\nwith open_key(\n \"HKLM\\\\SOFTWARE\\\\MyApp\",\n sub_key_access=winreg.KEY_READ\n) as key:\n values = key.enum_values()\n print(f\"Values: {values}\")\n```\n\n## Usage with [Robot Testing Framework](https://robotframework.org/)\n\n### Documentation\n\nhttps://shpaker.github.io/winregistry/winregistry.robot\n\n### Example\n\n```robotframework\n*** Variables ***\n${ SUITE_KEY_NAME } HKLM\\\\SOFTWARE\\\\_ROBOT_TESTS_\n${ SHORT_CASE_KEY_NAME } _CASE_KEY_\n${ CASE_KEY_NAME } ${ SUITE_KEY_NAME }\\\\${ SHORT_CASE_KEY_NAME }\n${ VALUE_NAME } some_testing_value\n\n*** Settings ***\nLibrary Collections\nLibrary winregistry.robot\nSuite Setup Create Registry Key ${ SUITE_KEY_NAME }\nSuite Teardown Delete Registry Key ${ SUITE_KEY_NAME }\n\n*** Test Cases ***\nTEST REGISTRY KEYS\n [Teardown] Delete Registry Key ${ CASE_KEY_NAME }\n\n ${ items } = Get Registry Key Sub Keys ${ SUITE_KEY_NAME }\n List Should Not Contain Value ${ items } ${ SHORT_CASE_KEY_NAME }\n Registry Key Should Not Exist ${ CASE_KEY_NAME }\n Create Registry Key ${ CASE_KEY_NAME }\n Registry Key Should Exist ${ CASE_KEY_NAME }\n ${ items } = Get Registry Key Sub Keys ${ SUITE_KEY_NAME }\n List Should Contain Value ${ items } ${ SHORT_CASE_KEY_NAME }\n\n\nTEST REGISTRY VALUES\n [Setup] Create Registry Key ${ CASE_KEY_NAME }\n [Teardown] Delete Registry Key ${ CASE_KEY_NAME }\n\n ${ items } = Get Registry Key Values Names ${ CASE_KEY_NAME }\n List Should Not Contain Value ${ items } ${ VALUE_NAME }\n Registry Value Should Not Exist ${ CASE_KEY_NAME } ${ VALUE_NAME }\n Create Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME } SZ\n Registry Value Should Exist ${ CASE_KEY_NAME } ${ VALUE_NAME }\n ${ items } = Get Registry Key Values Names ${ CASE_KEY_NAME }\n List Should Contain Value ${ items } ${ VALUE_NAME }\n ${ value } = Read Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME }\n Should Be Equal ${ value.data } ${ EMPTY }\n Set Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME } Remove me!\n ${ value } = Read Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME }\n Should Be Equal ${ value.data } Remove me!\n Delete Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME }\n```\n\n## Contributing\n\nContributions are welcome! Please read our contributing guidelines for more details.\n\n### Setting Up the Development Environment\n\nWe use `poetry` for dependency management and packaging. To set up your development environment, follow these steps:\n\n1. Install `poetry` if you haven't already:\n\n ```bash\n pip install poetry\n ```\n\n2. Install the project dependencies:\n\n ```bash\n poetry install --sync\n ```\n\n### Code Formatting and Linting\n\nWe use `ruff` for code formatting and linting. The following tasks are defined in the `Justfile` to help with these processes:\n\n- **Format the code:**\n\n ```bash\n just fmt\n ```\n\n- **Run the linter:**\n\n ```bash\n just lint\n ```\n\n## License\n\nThis project is licensed under the MIT License.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python library for interacting with the Windows registry",
"version": "2.1.0",
"project_urls": {
"Homepage": "https://github.com/shpaker/winregistry",
"Repository": "https://github.com/shpaker/winregistry"
},
"split_keywords": [
"windows",
" registry",
" regedit",
" winreg"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "147636d03ac958e79706f44e0c77fa9664b3f8c0a73ffdd708d6543c606b1e9f",
"md5": "e9401c4c62c3f866daa112940947ac2c",
"sha256": "7591bc93ba5513b389a0234dfa665ac0752e964bddf44757c266a3b754c941e1"
},
"downloads": -1,
"filename": "winregistry-2.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e9401c4c62c3f866daa112940947ac2c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 7951,
"upload_time": "2025-01-01T16:00:38",
"upload_time_iso_8601": "2025-01-01T16:00:38.680507Z",
"url": "https://files.pythonhosted.org/packages/14/76/36d03ac958e79706f44e0c77fa9664b3f8c0a73ffdd708d6543c606b1e9f/winregistry-2.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c561e7f3cd5df9ef559545fb36e1ecef8e89d64381de522fd3106c10e7e42bcf",
"md5": "13c6113a41f76a024eea58aecfb2b63c",
"sha256": "370c2872f9cf9a512ed344039efae2a2943eb36355bc867336ff049e0f9d1db4"
},
"downloads": -1,
"filename": "winregistry-2.1.0.tar.gz",
"has_sig": false,
"md5_digest": "13c6113a41f76a024eea58aecfb2b63c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9377,
"upload_time": "2025-01-01T16:00:40",
"upload_time_iso_8601": "2025-01-01T16:00:40.973041Z",
"url": "https://files.pythonhosted.org/packages/c5/61/e7f3cd5df9ef559545fb36e1ecef8e89d64381de522fd3106c10e7e42bcf/winregistry-2.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-01 16:00:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "shpaker",
"github_project": "winregistry",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "winregistry"
}