Blame lang/python/src/__init__.py

Packit d7e8d0
# Copyright (C) 2016 g10 Code GmbH
Packit d7e8d0
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
Packit d7e8d0
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
Packit d7e8d0
#
Packit d7e8d0
# This library is free software; you can redistribute it and/or
Packit d7e8d0
# modify it under the terms of the GNU Lesser General Public
Packit d7e8d0
# License as published by the Free Software Foundation; either
Packit d7e8d0
# version 2.1 of the License, or (at your option) any later version.
Packit d7e8d0
#
Packit d7e8d0
# This library is distributed in the hope that it will be useful,
Packit d7e8d0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit d7e8d0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit d7e8d0
# Lesser General Public License for more details.
Packit d7e8d0
#
Packit d7e8d0
# You should have received a copy of the GNU Lesser General Public
Packit d7e8d0
# License along with this library; if not, write to the Free Software
Packit d7e8d0
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
Packit d7e8d0
"""gpg: GnuPG Interface for Python (GPGME bindings)
Packit d7e8d0
Packit d7e8d0
Welcome to gpg, the GnuPG Interface for Python.
Packit d7e8d0
Packit d7e8d0
The latest release of this package may be obtained from
Packit d7e8d0
https://www.gnupg.org
Packit d7e8d0
Packit d7e8d0
FEATURES
Packit d7e8d0
--------
Packit d7e8d0
Packit d7e8d0
 * Feature-rich, full implementation of the GPGME library.  Supports
Packit d7e8d0
   all GPGME features.  Callback functions may be written in pure
Packit d7e8d0
   Python.  Exceptions raised in callbacks are properly propagated.
Packit d7e8d0
Packit d7e8d0
 * Ability to sign, encrypt, decrypt, and verify data.
Packit d7e8d0
Packit d7e8d0
 * Ability to list keys, export and import keys, and manage the keyring.
Packit d7e8d0
Packit d7e8d0
 * Fully object-oriented with convenient classes and modules.
Packit d7e8d0
Packit d7e8d0
QUICK EXAMPLE
Packit d7e8d0
-------------
Packit d7e8d0
Packit d7e8d0
    >>> import gpg
Packit d7e8d0
    >>> with gpg.Context() as c:
Packit d7e8d0
    >>> with gpg.Context() as c:
Packit d7e8d0
    ...     cipher, _, _ = c.encrypt("Hello world :)".encode(),
Packit d7e8d0
    ...                              passphrase="abc")
Packit d7e8d0
    ...     c.decrypt(cipher, passphrase="abc")
Packit d7e8d0
    ...
Packit d7e8d0
    (b'Hello world :)',
Packit d7e8d0
     <gpg.results.DecryptResult object at 0x7f5ab8121080>,
Packit d7e8d0
     <gpg.results.VerifyResult object at 0x7f5ab81219b0>)
Packit d7e8d0
Packit d7e8d0
GENERAL OVERVIEW
Packit d7e8d0
----------------
Packit d7e8d0
Packit d7e8d0
For those of you familiar with GPGME, you will be right at home here.
Packit d7e8d0
Packit d7e8d0
The python gpg module is, for the most part, a direct interface to the C GPGME
Packit Service 30b792
library.  However, it is re-packaged in a more Pythonic way -- object-oriented
Packit Service 30b792
with classes and modules.  Take a look at the classes defined here -- they
Packit Service 30b792
correspond directly to certain object types in GPGME for C.  For instance, the
Packit Service 30b792
following C code:
Packit d7e8d0
Packit d7e8d0
gpgme_ctx_t context;
Packit d7e8d0
gpgme_new(&context);
Packit d7e8d0
...
Packit d7e8d0
gpgme_op_encrypt(context, recp, 1, plain, cipher);
Packit d7e8d0
Packit d7e8d0
Translates into the following Python code:
Packit d7e8d0
Packit d7e8d0
context = core.Context()
Packit d7e8d0
...
Packit d7e8d0
context.op_encrypt(recp, 1, plain, cipher)
Packit d7e8d0
Packit Service 30b792
The Python module automatically does error-checking and raises Python exception
Packit Service 30b792
gpg.errors.GPGMEError when GPGME signals an error. getcode() and getsource() of
Packit Service 30b792
this exception return code and source of the error.
Packit d7e8d0
Packit d7e8d0
IMPORTANT NOTE
Packit d7e8d0
--------------
Packit Service 30b792
Packit d7e8d0
This documentation only covers a small subset of available GPGME functions and
Packit Service 30b792
methods.  Please consult the documentation for the C library for comprehensive
Packit Service 30b792
coverage.
Packit Service 30b792
Packit Service 30b792
This library uses Python's reflection to automatically detect the methods that
Packit Service 30b792
are available for each class, and as such, most of those methods do not appear
Packit Service 30b792
explicitly anywhere. You can use dir() python built-in command on an object to
Packit Service 30b792
see what methods and fields it has but their meaning can often only be found in
Packit Service 30b792
the GPGME documentation.
Packit d7e8d0
Packit Service 30b792
HIGHER LEVEL PYTHONIC LAYER
Packit Service 30b792
---------------------------
Packit Service 30b792
Packit Service 30b792
A more pythonic or intuitive layer is being added above the automatically
Packit Service 30b792
generated lower level bindings.  This is the recommended way to access the
Packit Service 30b792
module as if it is ever necessary to modify the underlying GPGME API, the
Packit Service 30b792
higher level methods will remain the same.
Packit Service 30b792
Packit Service 30b792
The quick example above is an example of this higher layer in action, whereas
Packit Service 30b792
the second example demonstrating the mapping to GPGME itself is the lower
Packit Service 30b792
layer.  The second example in the higher layer would be more like the encrypt
Packit Service 30b792
line in the quick example.
Packit d7e8d0
Packit d7e8d0
FOR MORE INFORMATION
Packit d7e8d0
--------------------
Packit Service 30b792
Packit d7e8d0
GnuPG homepage: https://www.gnupg.org/
Packit d7e8d0
GPGME documentation: https://www.gnupg.org/documentation/manuals/gpgme/
Packit Service 30b792
GPGME Python HOWTO: http://files.au.adversary.org/crypto/gpgme-python-howto-split/index.html
Packit Service 30b792
Packit Service 30b792
To view this documentation, run help(gpg) in Python or one of the following
Packit Service 30b792
commands outside of Python:
Packit Service 30b792
Packit Service 30b792
        pydoc gpg
Packit Service 30b792
        pydoc3 gpg
Packit Service 30b792
        python -m pydoc gpg
Packit Service 30b792
        python3 -m pydoc gpg
Packit d7e8d0
Packit d7e8d0
"""
Packit d7e8d0
Packit d7e8d0
from __future__ import absolute_import, print_function, unicode_literals
Packit d7e8d0
Packit d7e8d0
from . import core
Packit d7e8d0
from . import errors
Packit d7e8d0
from . import constants
Packit d7e8d0
from . import util
Packit d7e8d0
from . import callbacks
Packit d7e8d0
from . import version
Packit d7e8d0
from .core import Context
Packit d7e8d0
from .core import Data
Packit d7e8d0
Packit Service 30b792
del absolute_import, print_function, unicode_literals
Packit Service 30b792
Packit d7e8d0
# Interface hygiene.
Packit d7e8d0
Packit d7e8d0
# Drop the low-level gpgme that creeps in for some reason.
Packit d7e8d0
gpgme = None
Packit d7e8d0
del gpgme
Packit d7e8d0
Packit d7e8d0
# This is a white-list of symbols.  Any other will alert pyflakes.
Packit d7e8d0
_ = [Context, Data, core, errors, constants, util, callbacks, version]
Packit d7e8d0
del _
Packit d7e8d0
Packit Service 30b792
__all__ = [
Packit Service 30b792
    "Context", "Data", "core", "errors", "constants", "util", "callbacks",
Packit Service 30b792
    "version"
Packit Service 30b792
]