Skip to content

Retrieve API authorization tokens from the environment by it's names

License

Notifications You must be signed in to change notification settings

zaboal/tokens-retriever

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This package contains only a class with only one __init__ which retrieves the requested environment variables.

from tokens import Tokens  # as it all the that the package provides

For instance, we've to get some authorization tokens that already defined in the environment to interact with the Discord API and the Telegram API.

tokens = Tokens(["discord", "telegram"])

The class "Tokens" on initialization will retrieve as attributes these tokens from the environment as "PACKAGE_DISCORD_TOKEN" and "PACKAGE_TELEGRAM_TOKEN" or just "DISCORD_TOKEN" and "TELEGRAM_TOKEN" if the __name__ is undefined.

bot.run(tokens.discord)

The attribute "discord" should contain a string of the token if it has been in the environment, as the same as for "telegram".