Get values from a 'Single' DocType via Python?

I have a custom App that uses the Twilio API to send SMS/MMS messages. I have a whitelisted method that will make the API call.

I created a Single DocType called ‘Twilio Keys’ to store the Twilio account ID and secret.

How can I use Python to check if the Twilio Keys DocType exists, and then get the values from that record?

Hi @oguruma:

Try this (check your field names …)

config = frappe.get_single("Twilio Keys")
if config:
    account = config.twilio_account_id
    secret = config.twilio_account_secret

Other way:

account = frappe.db.get_single_value("Twilio Keys", "twilio_account_id")
secret = frappe.db.get_single_value("Twilio Keys", "twilio_account_secret")

Hope this helps.