apikeyper.database package

Module contents

class apikeyper.database.APIKeyDB(db_file_path=None)[source]

Bases: object

This class provides methods to interact with a SQLite database of API keys. It also supports exporting the database contents to JSON and XML formats.

db_file_path

The path to the SQLite database file.

Type:

str

conn

The connection to the SQLite database.

Type:

sqlite3.Connection

cursor

The cursor for executing SQL statements.

Type:

sqlite3.Cursor

add_key(service, key_name, key, added, status, revoked_on=None)[source]

Adds a new API key to the database.

Parameters:
  • service (str) – The service for the API key.

  • key_name (str) – The name of the API key.

  • key (str) – The API key.

  • added (str) – The date the key was added.

  • status (str) – The status of the API key.

  • revoked_on (str, optional) – The date the key was revoked. Defaults to None.

close()[source]

Closes the connection to the SQLite database.

export_db_as_json(export_path)[source]

Exports the contents of the database to a JSON file.

Parameters:

export_path (str) – The path to the output JSON file.

export_db_as_xml(export_path)[source]
list_keys_for_service(service)[source]

Lists all API keys for a specific service.

Parameters:

service (str) – The service to list keys for.

Returns:

A list of tuples representing the API keys for the service.

Return type:

list

list_services()[source]

Lists all unique services in the database.

Returns:

A list of all unique services.

Return type:

list