title: Pyrebase and Firebase Database Rules, how to deal with it with Python?
body: <p>I'm new in the world of Firebase and I'm using Pyrebase as library for Python 3.7. To test this library I've created a realtime database with public rules:</p>
  
  <pre><code>// These rules give anyone, even people who are not users of your app,
  // read and write access to your database
  {
    "rules": {
      ".read": true,
      ".write": true
    }
  }
  </code></pre>
  
  <p>It was easy to test the API. Now, I want to introduce more restrictive rules in my case are:</p>
  
  <pre><code>// These rules grant access to a node matching the authenticated
  // user ID from the Firebase auth token
  {
    "rules": {
      "users": {
        "$uid": {
          ".read": "$uid === auth.uid",
          ".write": "$uid === auth.uid"
        }
      }
    }
  }
  </code></pre>
  
  <p>But I'm encountering a lot of problems and doubts. My Python Code for authentication is this:</p>
  
  <pre><code>        firebase = pyrebase.initialize_app(self.config)
          self.username = email
          self.password = password
          self.db = firebase.database()
          self.auth = firebase.auth()
          # authenticate a user
          self.user = self.auth.sign_in_with_email_and_password(self.username, self.password)
  </code></pre>
  
  <p>Now when I try to read something for example:</p>
  
  <pre><code>#user_id is the name  of the child of main_document 
  db.child(self.main_document).child(user_id).get(self.user['idToken']).val() 
  </code></pre>
  
  <p>My Db structure is this:
  <a href="https://i.stack.imgur.com/P6QAe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P6QAe.png" alt="enter image description here"></a></p>
  
  <p>Reading from doc and trying to understand from rule syntax, I see that I need the UID of the user that I can obtain from <code>self.user</code> variable. But How can I "send" to Firebase in order to give it the possibility to make that match? I hope I was clearly :)</p>