Package: securedb
securedbsecuredb is a lightweight Python database framework to handle basic key-value encrypted data.pip install securedb --upgradeContent indexChangelogNew in 2.0.2 (Latest)New in 2.0.1New in 2.0.0New in 1.1.0DocumentationDB CreationKeyInitializationWriting keyswrite()write_many()Deletingdelete()delete_many()clear()Readingget()get_many()ChangelogNew in 2.0.2 (Latest)Bugfix in the get_many() functionPep8 compliantFixes in the docsNew in 2.0.1Fixed docs missing initialization instructionsNew in 2.0.0Completely redesigned db schema, now using single files for each database keyMaximum database storage size heavily increasedLower memory consumptionMapped every possible errorCustom key file pathNew in 1.1.0forcekwarg added in the initialization; seeinitializationYou don't need to manually encode the key during the initializationIf there is no error, all the functions now returnTrueUseless print() functions were removedSmoother error handlingDocumentationDB CreationKeyTo create a database, an encryption key is needed. To generate it, you can use the built-innewkey()function.importsecuredbsecuredb.newkey(keyfile="path/to/key/storage")# the "keyfile" kwarg is optional and default set to ".key".This will create a new file: it'll be named ".key" if nokeyfileis specified, else it'll be named as you want.
The key file is the file which contains the encryption key.Initializationimportsecuredbdb=securedb.Db(db_path,path_to_key,force=True)# path is the database storage location, key is the path to the key file and force is described below.Withforce=Truethe program will create a new db in the given path if no database is found.forceis optional and default set toFalse.
Remember that if you lost your key there will be no way to recover the database content.Writing keyswrite()Thewrite(key, value)function allows you to insert a single value into the database.keyis the value namevalueis the value data.keyis used to access the data, and must be an integer or a string;valuecan be anything such as boolean, integer, string, array, list, dictionary ecc.write_many()Thewrite_many(payload)function allows you to write many values in a single time.payloadis a dictionary with all the values you need to insert:{key: value, key1: value1, key2: value2}etc.
There isn't any limit regarding the size of the payload. For perfomance reasons, we suggest you to use payloads with a maximum size of 5mb, even if there is no software limit.Deletingdelete()Thedelete(key)function allows you to delete a single value from the database.keyis the value's key inside the database (seewrite) and must be a string or an integer.delete_many()Thedelete_many(payload)function allows you to delete many values at the same time.payloadis a list of the keys you want to delete:[key, key1, key2]etc.clear()Theclear()functions is a dangerous function that allows you to erease the whole database.
Be careful using it, because this action cannot be undone and the function doesn't ask confirmation before ereasing the database.Readingget()To read any value from the database, you need to use theget(key)function.keyis the key of the value you want to read (seewrite).get_many()To read any value from the database, you need to use theget_many(keys)function.keysis a list of the keys you want to read (seewrite).