pythonconfigurationsettings

Storing the secrets (passwords) in a separate file


What's the simplest way to store the application secrets (passwords, access tokens) for a Python script? I thought it'd be a *.yml file like in Ruby but surprisingly I found that it wasn't the case. So what is it then? What are the most simplest solutions?

I want to put them in a separate file because that way I'll be able not to push that file to a GitHub repository.


Solution

  • I think storing credentials inside another *py file is your safest bet. Then just import it. Example would look like this

    config.py

    username = "xy"
    password = "abcd"
    

    main.py

    import config
    login(config.username, config.password)