Skip to page content Skip to main navigation
English | Site Directory

e.g. "templates" or "datastore"

# The User Class

An instance of the User class represents a user with a Google account.

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

- Introduction
- User()
- Instance methods:
  - nickname()
  - email()

## Introduction

An instance of the User class represents a user with a Google account. An application 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 Users 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. See the note in User Objects.

## Constructor

class User(email=None)

  Represents a user with a Google account.

  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.

    The email address is not checked for validity when the User object is created. A User object with an email address that doesn't correspond to a valid Google account can be stored in the datastore, but will never match a real user.

## Instance Methods

A User instance provides the following methods:

nickname()

  Returns the "nickname" of the user, a displayable name. The nickname will be 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.

email()

  Returns the email address of the user. Applications should use nickname for displayable names.