RandomUser class

class randomuser.RandomUser(get_params=None, user_data=None, api_info=None)[source]
__init__(get_params=None, user_data=None, api_info=None)[source]

Initialize RandomUser object

Parameters:
  • get_params – (Optional) Dictionary mapping query parameter names to their values. See https://randomuser.me/documentation for details on parameters.
  • user_data – (Optional) If specified, this _data will be used instead of querying the API for user _data. Use in instances where the user _data has already been generated (e.g. restoring user _data, creating multiple users with single call to API using the ‘results’ parameter)
  • api_info – (Optional) If the user is being generated with the user_data parameter, the _info variable will be set to this. Otherwise, it will be ignored when generating a random user.
class PictureSize[source]

Constants for size parameter in RandomUser.get_picture()

LARGE = 'large'
MEDIUM = 'medium'
THUMBNAIL = 'thumbnail'
class Info[source]

Constants for RandomUser._info dictionary keys

SEED = 'seed'
RESULTS = 'results'
PAGE = 'page'
VERSION = 'version'
exception APIError(message)[source]

Exception to raise when the API query returns an error

Documentation on API errors: https://randomuser.me/documentation#errors

_data = {}

Dictionary where the random user data will be stored

_info = {}

Dictionary where info section of results will be stored

_generate_user()[source]

Query the randomuser.me API and store results in _data and _info

get_first_name(capitalize=True)[source]

Returns first name

Parameters:capitalize – (Default = True) Capitalize first letter if True
get_last_name(capitalize=True)[source]

Returns last name

Parameters:capitalize – (Default = True) Capitalize first letter if True
get_full_name(capitalize=True)[source]

Returns first and last name separated by a space

Parameters:capitalize – (Default = True) Capitalize first letter of each name if True
get_gender()[source]

Returns gender

get_dob(parse_time=False)[source]

Returns date of birth as a string in the format ‘%Y-%m-%dT%H:%M:%SZ’ (ISO 8601 standard)

Parameters:parse_time – (Default = False) If True, parse date of birth string using time.strptime() and return the results instead of a string
get_age()[source]

Returns the age of the user

get_nat()[source]

Returns nationality

get_street(capitalize=True)[source]

Returns street address

Parameters:capitalize – (Default = True) Capitalize first letter of words if True
get_city(capitalize=True)[source]

Returns city

Parameters:capitalize – (Default = True) Capitalize first letter of words if True
get_state(capitalize=True)[source]

Returns state

Parameters:capitalize – (Default = True) Capitalize first letter of words if True
get_postcode()[source]

Returns post code

get_zipcode()[source]

Returns zip code (wrapper for get_postcode())

get_coordinates()[source]

Returns a dictionary with keys ‘longitude’ and ‘latitude’ mapped to their respective values

_format_phone_number(phone_string, strip_parentheses=True, strip_hyphens=True)[source]

Takes a string representation of a phone number and strips characters based on parameter values

Parameters:
  • phone_string – The phone number as a string
  • strip_parentheses – (Default = True) Remove ‘(‘ and ‘)’ characters if True
  • strip_hyphens – (Default = True) Remove ‘-‘ characters if True
get_phone(strip_parentheses=False, strip_hyphens=False)[source]

Returns phone number as a string in the format ‘(###)-###-####’

Parameters:
  • strip_parentheses – (Default = False) Omit parentheses if True
  • strip_hyphens – (Default = False) Omit hyphens if True
get_cell(strip_parentheses=False, strip_hyphens=False)[source]

Returns cell phone number as a string in the format ‘(###)-###-####’

Parameters:
  • strip_parentheses – (Default = False) Omit parentheses if True
  • strip_hyphens – (Default = False) Omit hyphens if True
get_email()[source]

Returns email address

get_username()[source]

Returns username

get_password()[source]

Returns password

get_registered(parse_time=False)[source]

Returns registration date as a string in the format ‘%Y-%m-%dT%H:%M:%SZ’ (ISO 8601 standard)

Parameters:parse_time – (Default = False) If True, parse date string using time.strptime() and return the results instead of a string
get_registered_age()[source]

Returns the age (in years) since registration date

get_login_salt()[source]

Returns user login salt

get_login_md5()[source]

Returns user login md5

get_login_sha1()[source]

Returns user login sha1

get_login_sha256()[source]

Returns user login sha256

get_login_uuid()[source]

Returns user login uuid

get_id_type()[source]

Returns the ID type

get_id_number()[source]

Returns the ID number

get_id()[source]

Returns a dictionary mapping ‘type’ to ID type and ‘number’ to ID number

get_picture(size='large')[source]

Returns url to a .jpg of the generated user

Parameters:size – (Default = PictureSize.LARGE) The size of picture to return the url for. Size values are stored as constants in PictureSize nested class.
get_info()[source]

Returns a dictionary with information about the API query

Keys for the info dictionary are stored as constants in Info nested class.

_parse_time(date_string)[source]

Parses the date string format returned by the API and returns the time tuple result of time.strptime()

Parameters:date_string – The date string in the format ‘%Y-%m-%dT%H:%M:%SZ’
static generate_users(amount, get_params=None)[source]

Returns a list containing the specified amount of randomly generated users.

The Random User Generator API can generate multiple users in a single query instead of connecting once for each user and increasing load on both ends.

Parameters:
  • amount – The number of users to generate.
  • get_params – (Optional) Dictionary mapping query parameter names to their values. See https://randomuser.me/documentation for details on parameters.