pystatis
¶You don't need to do much to use pystatis
. Basically, the first time you import the package, it will create a config.ini
file under ~/.pystatis
. This file is used for storing settings, for example your credentials fpr the supported databases.
To set up your credentials, we need to ask you for your username and password. This is done by the setup_credentials()
function. It will ask you interactivly for the credentials, or you can set the following environmental variables:
PYSTATIS_GENESIS_API_USERNAME
PYSTATIS_GENESIS_API_PASSWORD
PYSTATIS_ZENSUS_API_USERNAME
PYSTATIS_ZENSUS_API_PASSWORD
PYSTATIS_REGIO_API_USERNAME
PYSTATIS_REGIO_API_PASSWORD
dotenv
is uses here to load a local .env
file that contains the above mentioned environmental variables so we don't have to input them.
from pathlib import Path
import dotenv
import pystatis
print("pystatis version: ", pystatis.__version__)
dotenv.load_dotenv()
# only execute if you want to delete your config file for test purposes
# pystatis.config.delete_config()
init_config
is called when loading pystatis, so a config with empty credentials will be created in your user home directory by default.
The only thing you have to do is to set up your user credentials.
You can do so either by:
PYSTATIS_GENESIS_API_USERNAME|PASSWORD
, and PYSTATIS_ZENSUS_API_USERNAME|PASSWORD
setup_credentials()
which will guide you through the processEven if you do 1. please call setup_credentials()
once as it will read out the environment variables and write the credentials to the config.ini
in your config dir.
pystatis.setup_credentials() # also part of config module
Once you have set up your credentials, they are stored in the config.ini
and in the config
object of the config.py
module. You don't have to know this as regular user, this is more internal knowledge.
Warning: The following code will print out the content of your config.ini
file with the credentials set, so please do not share or push this notebook with outputs enabled.
with open(Path.home() / ".pystatis" / "config.ini") as f:
print(f.read())