kppy
index
/usr/lib/python3.2/site-packages/kppy.py

This module implements the access to KeePass 1.x-databases.

 
Modules
       
Crypto.Cipher.AES
Crypto.Random
Crypto.Hash.SHA256
posixpath
struct

 
Classes
       
builtins.Exception(builtins.BaseException)
KPError
builtins.object
KPDB
StdEntry
StdGroup

 
class KPDB(builtins.object)
    KPDB represents the KeePass 1.x database.
 
Attributes:
- groups holds all groups of the database. (list of StdGroups)
- read_only declares if the file should be read-only or not (bool)
- filepath holds the path of the database (string)
- password is the passphrase to encrypt and decrypt the database (string)
- keyfile is the path to a keyfile (string)
 
Usage:
 
You can load a KeePass database by the filename and the passphrase or
create an empty database. It's also possible to open the database read-only
and to create a new one.
 
Example:
 
from kppy import KPDBKPError
 
try;
    db = KPDB(filepath, passphrase)
except KPError as e:
    print(e)
 
  Methods defined here:
__init__(self, filepath=None, password=None, keyfile=None, read_only=False, new=False)
Initialize a new or an existing database.
 
If a 'filepath' and a 'masterkey' is passed 'load' will try to open
a database. If 'True' is passed to 'read_only' the database will open
read-only. It's also possible to create a new one, just pass 'True' to
new. This will be ignored if a filepath and a masterkey is given this
will be ignored.
close(self)
This method closes the database correctly.
create_entry(self, group=None, title='', image=1, url='', username='', password='', comment='', y=2999, mon=12, d=28, h=23, min_=59, s=59)
This method creates a new entry.
 
The group which should hold the entry is needed.
 
image must be an unsigned int >0, group a StdGroup.
 
It is possible to give an expire date in the following way:
    - y is the year between 1 and 9999 inclusive
    - mon is the month between 1 and 12
    - d is a day in the given month
    - h is a hour between 0 and 23
    - min_ is a minute between 0 and 59
    - s is a second between 0 and 59
 
The special date 2999-12-28 23:59:59 means that entry expires never.
create_group(self, title=None, parent=None, image=1, y=2999, mon=12, d=28, h=23, min_=59, s=59)
This method creates a new group.
 
A group title is needed or no group will be created.
 
If a parent is given, the group will be created as a sub-group.
 
title must be a string, image an unsigned int >0 and parent a StdGroup.
 
With y, mon, d, h, min_ and s you can set an expiration date like on
entries.
load(self)
This method opens an existing database.
 
self.password/self.keyfile and self.filepath must be set.
lock(self)
This method locks the database.
move_entry(self, entry=None, group=None)
Move an entry to another group.
 
StdGroup group and a StdEntry entry are needed.
move_entry_in_group(self, entry=None, index=None)
Move entry to another position inside a group.
 
An entry and a valid index to insert the entry in the
entry list of the holding group is needed. 0 means
that the entry is moved to the first position 1 to
the second and so on.
move_group(self, group=None, parent=None)
Append group to a new parent.
 
group and parent must be StdGroup-instances.
move_group_in_parent(self, group=None, index=None)
Move group to another position in group's parent.
 
index must be a valid index of group.parent.groups
remove_entry(self, entry=None)
This method can remove entries.
 
The StdEntry-object entry is needed.
remove_group(self, group=None)
This method removes a group.
 
The group needed to remove the group.
 
group must be a StdGroup.
save(self, filepath=None, password=None, keyfile=None)
This method saves the database.
 
It's possible to parse a data path to an alternative file.
unlock(self, password=None, keyfile=None)
Unlock the database.
 
masterkey is needed.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class KPError(builtins.Exception)
    KPError is a exception class to handle exception raised by KPDB.
 
Usage:
 
Handle KPError like every else expection. You can print the error message
via an expection instance.
 
Example:
 
try:
    ...
except KPError as e:
    print(e)
 
 
Method resolution order:
KPError
builtins.Exception
builtins.BaseException
builtins.object

Methods defined here:
__init__(self, error)
__str__(self)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from builtins.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from builtins.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
with_traceback(...)
Exception.with_traceback(tb) --
set self.__traceback__ to tb and return self.

Data descriptors inherited from builtins.BaseException:
__cause__
exception cause
__context__
exception context
__dict__
__traceback__
args

 
class StdEntry(builtins.object)
    StdEntry represents a simple entry of a KeePass 1.x database.
 
Attributes:
    - uuid is an "Universal Unique ID", that is it identifies the entry (16 bytes string)
    - group_id is the id of the holding group (unsigned int)
    - group is the holding StdGroup instance
    - image is the image number (unsigned int)
    - title is the entry title (string)
    - url is an url to a website where the login information of this entry (string)
      can be used
    - username is an username (string)
    - password is the password (string)
    - creation is the creation date of this entry (datetime-instance)
    - last_mod is the date of the last modification (datetime-instance)
    - last_access is the date of the last access (datetime-instance)
    - expire is the date when the entry should expire (datetime-instance)
    - comment is a comment string
 
  Methods defined here:
__init__(self, group_id=None, group=None, image=1, title=None, url=None, username=None, password=None, comment=None, creation=None, last_mod=None, last_access=None, expire=None, uuid=None, binary_desc=None, binary=None)
Initialize a StdEntry-instance.
 
It's recommended to use create_entry of StdGroup or KPDB.
move_entry(self, group=None)
This method moves the entry to another group.
 
group must be a valid StdGroup-instance.
move_entry_in_group(self, index)
This method moves the entry to another position in the group.
 
index must be a valid index for self.group.entries.
remove_entry(self)
This method removes this entry.
set_comment(self, comment=None)
This method is used to the the comment.
 
comment must be a string.
set_expire(self, y=2999, mon=12, d=28, h=23, min_=59, s=59)
This method is used to change the expire date of an entry.
 
    - y is the year between 1 and 9999 inclusive
    - mon is the month between 1 and 12
    - d is a day in the given month
    - h is a hour between 0 and 23
    - min_ is a minute between 0 and 59
    - s is a second between 0 and 59
 
The special date 2999-12-28 23:59:59 means that  expires never. If
only an uuid is given the expire date will set to this one.
set_image(self, image=None)
This method is used to set the image number.
 
image must be an unsigned int.
set_password(self, password=None)
This method is used to set the password.
 
password must be a string.
set_title(self, title=None)
This method is used to change an entry title.
 
A new title string is needed.
set_url(self, url=None)
This method is used to set the url.
 
url must be a string.
set_username(self, username=None)
This method is used to set the username.
 
username must be a string.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class StdGroup(builtins.object)
    StdGroup represents a simple group of a KeePass 1.x database.
 
Attributes:
- id_ is the group id (unsigned int)
- title is the group title (string)
- image is the image number used in KeePassX (unsigned int)
- level is needed to create the group tree (unsigned int)
- parent is the previous group (StdGroup)
- children is a list of all following groups (list of StdGroups)
- entries is a list of all entries of the group (list of StdEntrys)
- db is the database which holds the group (KPDB)
 
  Methods defined here:
__init__(self, id_=None, title=None, image=1, db=None, level=0, parent=None, children=[], entries=[], creation=None, last_mod=None, last_access=None, expire=None, flags=None)
Initialize a StdGroup-instance.
 
It's recommended to use create_group of KPDB and not this directly.
create_entry(self, title='', image=1, url='', username='', password='', comment='', y=2999, mon=12, d=28, h=23, min_=59, s=59)
This method creates an entry in this group.
 
Compare to StdEntry for information about the arguments.
 
One of the following arguments is needed:
 
- title
- url
- username
- password
- comment
move_group(self, parent)
calls self.db.move_group
move_group_in_parent(self, index)
calls move_group_in_parent
remove_group(self)
This method calls remove_group of the holding db
set_expire(self, y=2999, mon=12, d=28, h=23, min_=59, s=59)
This method is used to change the expire date of a group
 
    - y is the year between 1 and 9999 inclusive
    - mon is the month between 1 and 12
    - d is a day in the given month
    - h is a hour between 0 and 23
    - min_ is a minute between 0 and 59
    - s is a second between 0 and 59
 
The special date 2999-12-28 23:59:59 means that group expires never. If
only an uuid is given the expire date will set to this one.
set_image(self, image=None)
This method is used to change the image number of a group.
 
image must be an unsigned int >0.
set_title(self, title=None)
This method is used to change a group title.
 
title must be a string.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
remove(...)
remove(path)
 
Remove a file (same as unlink(path)).