The User Class

An instance of the User class represents an authenticated user of the app.

User is provided by the google.appengine.api.users module.

  1. Introduction
  2. User()
  3. Instance methods:


An instance of the User class represents an authenticated user of the application. The user is authenticated using the authentication option set for the app: either Google Accounts, Google Apps account, or OpenID. (Note that the support for OpenID is experimental.) An app can get a User instance that represents the user currently signed in to the application by calling the constructor with no arguments, or by calling the users.get_current_user() function. If the current user is not signed in, the User constructor raises a UserNotFoundError. (users.get_current_user() does not raise an exception if the user is not signed in.)

User objects are comparable. If two User objects are equal, then both objects represent the same user. However, be careful: if you store a user's User object and then that user changes their email address, a new User object won't match the stored one. If you need an ID that represents the user regardless of account changes, use user_id().


class User(email=None, federated_identity=None)

Represents an authenticated user of the app.



The email address of the desired user. If omitted, the object will represent the current user (the user making the request). If no address is given and the current user is not signed in, a UserNotFoundError is raised.

Only RFC compliant email addresses can match a real user. You can, however, store non-RFC-compliant email addresses in the datastore.


The OpenID identifier of the desired user.

Instance Methods

A User instance provides the following methods:


Returns the "nickname" of the user, a displayable name. For Google Accounts users, the nickname is either the "name" portion of the user's email address if the address is in the same domain as the application, or the user's full email address otherwise. For OpenID users, the nickname is the OpenID identifier.


Returns the email address of the user. If you use OpenID, you should not rely on this email address to be correct. Applications should use nickname for displayable names.


If the email address is associated with a Google account, user_id returns the unique permanent ID of the user, a str. This ID is always the same for the user regardless of whether the user changes her email address.

If the email address is not associated with a Google account, user_id returns None.

Note: If your application constructs the User instance, the API will not set a value for user_id and it returns None.


Returns the user's OpenID identifier.


Returns the URL of the user's OpenID provider.