title: How to check if an Airflow user already exists in the airflow DB in Python code
body: <p>I am new to airflow and got a task to add basic auth for Airflow Webserver. I implemented that using the below python code(from <a href="https://airflow.apache.org/docs/apache-airflow/1.10.1/security.html#password" rel="nofollow noreferrer">https://airflow.apache.org/docs/apache-airflow/1.10.1/security.html#password</a>). I was able to create a user and authenticate to Airflow Webserver using that user/password.</p>
  <pre><code># navigate to the airflow installation directory
  $ cd ~/airflow
  $ python
  Python 2.7.9 (default, Feb 10 2015, 03:28:08)
  Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
  &gt;&gt;&gt; import airflow
  &gt;&gt;&gt; from airflow import models, settings
  &gt;&gt;&gt; from airflow.contrib.auth.backends.password_auth import PasswordUser
  &gt;&gt;&gt; user = PasswordUser(models.User())
  &gt;&gt;&gt; user.username = 'new_user_name'
  &gt;&gt;&gt; user.email = 'new_user_email@example.com'
  &gt;&gt;&gt; user.password = 'set_the_password'
  &gt;&gt;&gt; session = settings.Session()
  &gt;&gt;&gt; session.add(user)
  &gt;&gt;&gt; session.commit()
  &gt;&gt;&gt; session.close()
  &gt;&gt;&gt; exit()
  </code></pre>
  <p>However, now I need to make sure that I only update the user instead of creating if the user already exists in airflow DB.
  Is there an attribute for the <code>session</code> object like <code>get</code> or <code>getusers</code> to know if the user already exists.</p>
  <p>I am able to see the user created in airflowdb.users table in the database. But, I need to check from Python code instead.</p>
  <p>Thanks in advance for your help.</p>