title: How to handle user authentication for a CLI in Python using Click
body: <p>I'm using the very good Click framework to build a Python CLI that acts as a "wrapper" around a set of complex REST APIs. I've used the <a href="https://github.com/mitsuhiko/click/tree/master/examples" rel="nofollow noreferrer">"complex" example</a> in order to have good boilerplate code to build the rest of CLI.</p>
  
  <p>However, since the CLI itself communicates with REST APIs, I need a bit of configuration for each command. Example: user authentication (id, password, etc.), and, if different from the default one, the URL to API server.</p>
  
  <p>I could force the user to put these configuration as parameters for each command, but this would be really annoying when executing many commands (the user has to insert his auth details for every command).</p>
  
  <p>Is there a way to have the user enter his credentials at the first command in order to have his uid/pwd persist for the entire session (like the mysql-cli, for example), and, after executing the commands he needed, "logout" from the CLI?</p>