English ▼
Skip to page content Skip to main navigation
e.g. "templates" or "datastore"

# 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.

- Introduction
- User()
- Instance methods:
  - nickname()
  - email()
  - user_id()
  - federated_identity()
  - federated_provider()

## Introduction

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. 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.

A User object can be the value of a datastore entity property. See Types and Property Classes.

Note: A user can change the email address for a Google account. If you need an ID that represents the user regardless of account changes, use `user_id()`.

## Constructor

class User(email=None, federated_identity=None)

  Represents an authenticated user of the app.

  Arguments:

  email

    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.

  federated_identity

    The OpenID identifier of the desired user.

## Instance Methods

A User instance provides the following methods:

nickname()

  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.

email()

  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.

user_id()

  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`.

federated_identity()

  Returns the user's OpenID identifier.

federated_provider()

  Returns the URL of the user's OpenID provider.