3. Custom Databases


While all data saved in these databases is encrypted where necessary, please make sure that user accounts, user privileges, backup, etc. are properly configured in the database. Just because the data is encrypted, an unauthorized user can still delete it.


Any database configuration changes will result in Krptn assuming that all data has been migrated to the new database and is ready to use.

Internally, these strings are passed to SQLAlchemy to create an engine. To add extra connection parameters, please refer to SQLAlchemy’s and/or your chosen database’s SQL Driver documentation.

Since many database connection URLs are dificult (and sometimes impossible) to type as strings, you can use SQLAlchemy’s API to create them. Please read this section for more information.

Please set these strings at:

1krypton.configs.SQLDefaultCryptoDBpath = # for DB used by Crypto Class
2krypton.configs.SQLDefaultKeyDBpath =  # for DB used by Key Management System (you most likely don't need this)
3krypton.configs.SQLDefaultUserDBpath = # for DB used by User Authentication System

3.1. Microsoft SQL Server

You need to install pyodbc and Microsoft ODBC Driver for SQL Server

The string that you need to pass to this extension should look like this:

1"mssql+pyodbc://user:password@host:port/dbname?driver=odbc driver e.g:ODBC+Driver+18+for+SQL+Server"

If you are only doing development, you may add the following to prevent installing an SSL certificate:


To use Windows authentication, please remove user:password from the string.

3.2. MySQL

Please install mysqlclient.


3.3. SQLite


3.4. PostgreSQL

Please install psycopg2.


3.5. More complex connection strings

In places where more complex connection strings are needed, you can import SQLAlchemy’s API to do it.

For example, to connect to MSSQL LocalDB (of course replace server and driver with your own values):

1from sqlalchemy.engine import URL
2connection_string = "DRIVER={ODBC Driver 18 for SQL Server};Server=(localdb)\MSSQLLocalDB;Integrated Security=true'"
3connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": connection_string})

And then pass it to Krptn:

1krypton.configs.SQLDefaultUserDBpath = connection_url

In the above example, connection_url will have the following content: mssql+pyodbc://?odbc_connect=DRIVER%3D%7BODBC+Driver+18+for+SQL+Server%7D%3BServer%3D%28localdb%29%5CMSSQLLocalDB%3BIntegrated+Security%3Dtrue%27. This would be truly horrible to type hence SQLAlchemy’s API is very handy.