<commit_before>Using PGPy
----------

Installation
^^^^^^^^^^^^

PGPy can be obtained from PyPI using pip:

.. code-block:: bash

    $ pip install PGPy


Using PGPy is quite simple. For all examples given below, use the following import statement::

    import pgpy

Loading Keys
^^^^^^^^^^^^

The first thing you will always want to do is load one or more keys. PGPy understands a wide variety of formats.

You can load ASCII armored keys or GPG keyrings directly using a path, URL, file-like object, string, byte string,
or a list of any of those formats::

    asciikey = pgpy.PGPKeyring("path/to/key.asc")
    keyring = pgpy.PGPKeyring("path/to/keyring.gpg")
    pubsec = pgpy.PGPKeyring(["/home/user/.gnupg/pubring.gpg", "/home/user/.gnupg/secring.gpg"])
    ubuntupubkey = pgpy.PGPKeyring("http://us.archive.ubuntu.com/ubuntu/project/ubuntu-archive-keyring.gpg")


and additional keys can be loaded as you go::

    pubsec = pgpy.PGPKeyring(["/home/user/.gnupg/pubring.gpg", "/home/user/.gnupg/secring.gpg"])
    pubsec.load("path/to/another/key")
    pubsec.load(["another/pubring.gpg", "anther/secring.gpg"])


PGPKeyring also accepts URLs, file-like objects, strings, and byte strings.

Using Keys
^^^^^^^^^^

Once you have some keys loaded, you probably want to do something with them.
The basic pattern for using keys is with a context management block. The :py:meth:`PGPKeyring.key` method
provides that context management::

    with pubsec.key("DEADBEEF"):
        # You can sign things by specifying a private key.
        # If the key is protected, you may need to unlock it first, otherwise, :py:meth:`PGPKeyring.sign` will raise an exception<commit_msg>fixed a typo<commit_after>Using PGPy
----------

Installation
^^^^^^^^^^^^

PGPy can be obtained from PyPI using pip:

.. code-block:: bash

    $ pip install PGPy


Using PGPy is quite simple. For all examples given below, use the following import statement::

    import pgpy

Loading Keys
^^^^^^^^^^^^

The first thing you will always want to do is load one or more keys. PGPy understands a wide variety of formats.

You can load ASCII armored keys or GPG keyrings directly using a path, URL, file-like object, string, byte string,
or a list of any of those formats::

    asciikey = pgpy.PGPKeyring("path/to/key.asc")
    keyring = pgpy.PGPKeyring("path/to/keyring.gpg")
    pubsec = pgpy.PGPKeyring(["/home/user/.gnupg/pubring.gpg", "/home/user/.gnupg/secring.gpg"])
    ubuntupubkey = pgpy.PGPKeyring("http://us.archive.ubuntu.com/ubuntu/project/ubuntu-archive-keyring.gpg")


and additional keys can be loaded as you go::

    pubsec = pgpy.PGPKeyring(["/home/user/.gnupg/pubring.gpg", "/home/user/.gnupg/secring.gpg"])
    pubsec.load("path/to/another/key")
    pubsec.load(["another/pubring.gpg", "another/secring.gpg"])


PGPKeyring also accepts URLs, file-like objects, strings, and byte strings.

Using Keys
^^^^^^^^^^

Once you have some keys loaded, you probably want to do something with them.
The basic pattern for using keys is with a context management block. The :py:meth:`PGPKeyring.key` method
provides that context management::

    with pubsec.key("DEADBEEF"):
        # You can sign things by specifying a private key.
        # If the key is protected, you may need to unlock it first, otherwise, :py:meth:`PGPKeyring.sign` will raise an exception
{'fraction_non_alphanumeric': 0.12440191387559808, 'fraction_numerical': 0.0, 'mean_word_length': 3.7717546362339514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4120255', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1046, 'n_words': 365}