Package: lib-registry
lib_registryVersion v2.0.10 as of 2023-07-21 seeChangeloga more pythonic way to access the windows registry as winregcommand line interface is prepared - if someone needs to use it via commandline, give me a note.automated tests, Github Actions, Documentation, Badges, etc. are managed withPizzaCutter(cookiecutter on steroids)Python version required: 3.8.0 or newertested on recent linux with python 3.8, 3.9, 3.10, 3.11, 3.12-dev, pypy-3.9, pypy-3.10 - architectures: amd64100% code coverage, flake8 style checking ,mypy static type checking ,tested underLinux, macOS, Windows, automatic daily builds and monitoringTry it OnlineUsageUsage from CommandlineInstallation and UpgradeRequirementsAcknowledgementsContributeReport IssuesPull RequestCode of ConductLicenseChangelogTry it OnlineYou might try it right away in Jupyter Notebook by using the “launch binder” badge, or clickhereUsagepython methods:Registry ObjectclassRegistry(object):def__init__(self,key:Union[None,str,int]=None,computer_name:Optional[str]=None):"""
        The Registry Class, to create the registry object.
        If a key is passed, a connection to the hive is established.

        Parameter
        ---------

        key:
            the predefined handle to connect to,
            or a key string with the hive as the first part (everything else but the hive will be ignored)
            or None (then no connection will be established)
        computer_name:
            the name of the remote computer, of the form r"\\computer_name" or "computer_name". If None, the local computer is used.

        Exceptions
        ----------
            RegistryNetworkConnectionError      if we can not reach target computer
            RegistryHKeyError                   if we can not connect to the hive
            winreg.ConnectRegistry              auditing event

        Examples
        --------

        >>> # just create the instance without connection
        >>> registry = Registry()

        >>> # test connect at init:
        >>> registry = Registry('HKCU')

        >>> # test invalid hive as string
        >>> Registry()._reg_connect('SPAM')
        Traceback (most recent call last):
            ...
        lib_registry.RegistryHKeyError: invalid KEY: "SPAM"

        >>> # test invalid hive as integer
        >>> Registry()._reg_connect(42)
        Traceback (most recent call last):
            ...
        lib_registry.RegistryHKeyError: invalid HIVE KEY: "42"

        >>> # test invalid computer to connect
        >>> Registry()._reg_connect(winreg.HKEY_LOCAL_MACHINE, computer_name='some_unknown_machine')
        Traceback (most recent call last):
            ...
        lib_registry.RegistryNetworkConnectionError: The network address "some_unknown_machine" is invalid

        >>> # test invalid network Path
        >>> Registry()._reg_connect(winreg.HKEY_LOCAL_MACHINE, computer_name=r'localhost\\ham\\spam')
        Traceback (most recent call last):
            ...
        lib_registry.RegistryNetworkConnectionError: The network path to "localhost\\ham\\spam" was not found

        """create_keydefcreate_key(self,key:Union[str,int],sub_key:str='',exist_ok:bool=True,parents:bool=False)->winreg.HKEYType:"""
    Creates a Key, and returns a Handle to the new key


    Parameter
    ---------
    key
      either a predefined HKEY_* constant,
      a string containing the root key,
      or an already open key
    sub_key
      a string with the desired subkey relative to the key
    exist_ok
      bool, default = True
    parents
      bool, default = false


    Exceptions
    ----------
    RegistryKeyCreateError
        if we can not create the key


    Examples
    --------

    >>> # Setup
    >>> registry = Registry()
    >>> # create a key
    >>> registry.create_key(r'HKCU\\Software')
    <...PyHKEY object at ...>

    >>> # create an existing key, with exist_ok = True
    >>> registry.create_key(r'HKCU\\Software\\lib_registry_test', exist_ok=True)
    <...PyHKEY object at ...>

    >>> # create an existing key, with exist_ok = False (parent existing)
    >>> registry.create_key(r'HKCU\\Software\\lib_registry_test', exist_ok=False)
    Traceback (most recent call last):
        ...
    lib_registry.RegistryKeyCreateError: can not create key, it already exists: HKEY_CURRENT_USER...lib_registry_test

    >>> # create a key, parent not existing, with parents = False
    >>> registry.create_key(r'HKCU\\Software\\lib_registry_test\\a\\b', parents=False)
    Traceback (most recent call last):
        ...
    lib_registry.RegistryKeyCreateError: can not create key, the parent key to "HKEY_CURRENT_USER...b" does not exist

    >>> # create a key, parent not existing, with parents = True
    >>> registry.create_key(r'HKCU\\Software\\lib_registry_test\\a\\b', parents=True)
    <...PyHKEY object at ...>

    >>> # TEARDOWN
    >>> registry.delete_key(r'HKCU\\Software\\lib_registry_test', delete_subkeys=True)

    """delete_keydefdelete_key(self,key:Union[str,int],sub_key:str='',missing_ok:bool=False,delete_subkeys:bool=False)->None:"""
    deletes the specified key, this method can delete keys with subkeys.
    If the method succeeds, the entire key, including all of its values, is removed.

    Parameter
    ---------
    key
      either a predefined HKEY_* constant,
      a string containing the root key,
      or an already open key
    sub_key
      a string with the desired subkey relative to the key
    missing_ok
      bool, default = False
    delete_subkeys
      bool, default = False

    Exceptions
    ----------
        RegistryKeyDeleteError  If the key does not exist,
        RegistryKeyDeleteError  If the key has subkeys and delete_subkeys = False

    >>> # Setup
    >>> registry = Registry()
    >>> # create a key, parent not existing, with parents = True
    >>> registry.create_key(r'HKCU\\Software\\lib_registry_test\\a\\b', parents=True)
    <...PyHKEY object at ...>

    >>> # Delete a Key
    >>> assert registry.key_exist(r'HKCU\\Software\\lib_registry_test\\a\\b') == True
    >>> registry.delete_key(r'HKCU\\Software\\lib_registry_test\\a\\b')
    >>> assert registry.key_exist(r'HKCU\\Software\\lib_registry_test\\a\\b') == False

    >>> # Try to delete a missing Key
    >>> registry.delete_key(r'HKCU\\Software\\lib_registry_test\\a\\b')
    Traceback (most recent call last):
        ...
    lib_registry.RegistryKeyDeleteError: can not delete key none existing key ...

    >>> # Try to delete a missing Key, missing_ok = True
    >>> registry.delete_key(r'HKCU\\Software\\lib_registry_test\\a\\b')
    Traceback (most recent call last):
        ...
    lib_registry.RegistryKeyDeleteError: can not delete key none existing key ...

    >>> # Try to delete a Key with subkeys
    >>> registry.delete_key(r'HKCU\\Software\\lib_registry_test')
    Traceback (most recent call last):
        ...
    lib_registry.RegistryKeyDeleteError: can not delete none empty key ...

    >>> # Try to delete a Key with subkeys, delete_subkeys = True
    >>> registry.delete_key(r'HKCU\\Software\\lib_registry_test', delete_subkeys=True)
    >>> assert registry.key_exist(r'HKCU\\Software\\lib_registry_test') == False

    >>> # Try to delete a Key with missing_ok = True
    >>> registry.delete_key(r'HKCU\\Software\\lib_registry_test', missing_ok=True)

    """key_existsdefkey_exist(self,key:Union[str,int],sub_key:str='')->bool:"""
    True if the given key exists

    Parameter
    ---------
    key
      either a predefined HKEY_* constant,
      a string containing the root key,
      or an already open key

    sub_key
      a string with the desired subkey relative to the key


    Examples
    --------

    >>> Registry().key_exist(r'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion')
    True
    >>> Registry().key_exist(r'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\DoesNotExist')
    False

    """Usage from CommandlineUsage: lib_registry [OPTIONS] COMMAND [ARGS]...

  a more pythonic way to access the windows registry as winreg

Options:
  --version                     Show the version and exit.
  --traceback / --no-traceback  return traceback information on cli
  -h, --help                    Show this message and exit.

Commands:
  info  get program informationsInstallation and UpgradeBefore You start, its highly recommended to update pip and setup tools:python -m pip --upgrade pip
python -m pip --upgrade setuptoolsto install the latest release from PyPi via pip (recommended):python -m pip install --upgrade lib_registryto install the latest release from PyPi via pip, including test dependencies:python -m pip install --upgrade lib_registry[test]to install the latest version from github via pip:python -m pip install --upgrade git+https://github.com/bitranox/lib_registry.gitinclude it into Your requirements.txt:# Insert following line in Your requirements.txt:
# for the latest Release on pypi:
lib_registry

# for the latest development version :
lib_registry @ git+https://github.com/bitranox/lib_registry.git

# to install and upgrade all modules mentioned in requirements.txt:
python -m pip install --upgrade -r /<path>/requirements.txtto install the latest development version, including test dependencies from source code:# cd ~
$ git clone https://github.com/bitranox/lib_registry.git
$ cd lib_registry
python -m pip install -e .[test]via makefile:
makefiles are a very convenient way to install. Here we can do much more,
like installing virtual environments, clean caches and so on.# from Your shell's homedirectory:$gitclonehttps://github.com/bitranox/lib_registry.git$cdlib_registry# to run the tests:$maketest# to install the package$makeinstall# to clean the package$makeclean# uninstall the package$makeuninstallRequirementsfollowing modules will be automatically installed :## Project Requirementsclickcli_exit_toolsfake_winregAcknowledgementsspecial thanks to “uncle bob” Robert C. Martin, especially for his books on “clean code” and “clean architecture”ContributeI would love for you to fork and send me pull request for this project.
-please ContributeLicenseThis software is licensed under theMIT license—Changelognew MAJOR version for incompatible API changes,new MINOR version for added functionality in a backwards compatible mannernew PATCH version for backwards compatible bug fixestasks:test if caching of handles make sense, especially on networkdocumentation updatepathlib-like Interfacejupyter notebook updatev2.0.10update jupyter notebookset secrets for pypi uploadv2.0.92023-07-20:correct error in set_value with value_type=winreg.REG_NONEv2.0.82023-07-20:require minimum python 3.8remove python 3.7 testsintroduce PEP517 packaging standardintroduce pyproject.toml build-systemremove mypy.iniremove pytest.iniremove setup.cfgremove setup.pyremove .bettercodehub.ymlremove .travis.ymlupdate black configclean ./tests/test_cli.pyadd codeql badgemove 3rd_party_stubs outside the src directory to./.3rd_party_stubsadd pypy 3.10 testsadd python 3.12-dev testsv2.0.72020-10-10: fix minor bugsv2.0.62020-10-09: service releaseupdate travis build matrix for linux 3.9-devupdate travis build matrix (paths) for windows 3.9 / 3.10v2.0.52020-08-08: service releasefix documentationfix travisdeprecate pycodestyleimplement flake8v2.0.42020-08-01: fix pypi deployv2.0.32020-07-31: fix travis buildv2.0.22020-07-29: feature releaseuse the new pizzacutter templateuse cli_exit_toolsv2.0.12020-07-16: feature releasefix cli testenable traceback option on cli errorscorrected error in DeleteKey, missing_okv2.0.02020-07-14feature releasefix setup.py for deploy on pypifix travis for pypi deploy testingv2.0.0a02020-07-13intermediate releasestart to implement additional pathlib-like interfaceimplement fake-winreg to be able to develop and test under linuxv1.0.42020-07-08patch releasenew click CLIuse PizzaCutter Templateadded jupyter notebookreorganized modules and importupdated documentationv1.0.32019-09-02: strict mypy type checking, housekeepingv1.0.22019-04-10: initial PyPi releasev1.0.12019-03-29: prevent import error when importing under linuxv1.0.02019-03-28: Initial public release