Models

class TheNounProjectAPI.models.Model

Model is a base class to be used as a superclass for conveniently accessing data. All of the json returned by the API is parsed through this model, and stored under the json attribute.

Let’s assume the json looks like this:

{
    "author": {
        "location": "US",
        "name": "mnmly",
        "permalink": "/mnmly",
        "username": "mnmly"
    },
    "author_id": "1",
    "date_created": "2012-02-22 13:32:49",
    "date_updated": "2012-02-22 13:33:00",
    "description": "",
    "icon_count": "3",
    "id": "7",
    "is_collaborative": "",
    "is_featured": "0",
    "is_published": "0",
    "is_store_item": "1",
    "name": "Bicycle",
    "permalink": "/mnmly/collection/bicycle",
    "slug": "bicycle",
    "sponsor": {},
    "sponsor_campaign_link": "",
    "sponsor_id": "",
    "tags": [],
    "template": "24"
}

This data may then be accessed in any of the following ways:

# (A) Standard way for accessing a dict
model.json["author"]["username"]

# This standard way may also be applied directly to the model object.
model["author"]["username"]

# Dot notation may also be used, both on the json attribute, or on the model object.
model.json.author.username
model.author.username
json

The json data returned by the API, as a DotDict instance.

response

The requests.Response object returned by sending the request.

classmethod parse(data, response=None)

Constructs and returns an instance of (sub)class, with the json attribute set to a conveniently accessible DotDict object, filled with data.

class TheNounProjectAPI.models.ModelList

Bases: list

ModelList is a base class to be used as a superclass for conveniently accessing lists of Model objects.

classmethod parse(data, instance_class, main_keys, response=None)

Constructs and returns a list of instances of instance_class, a subclass of Model. In addition, this list has some additional attributes based on the data dictionary.

class TheNounProjectAPI.models.CollectionModel

Bases: TheNounProjectAPI.models.Model

CollectionModel is a subclass of Model, with different attributes displayed when printed. See Collection for more information regarding what attributes comes with this object.

classmethod parse(data, response=None)

Constructs and returns an instance of (sub)class, with the json attribute set to a conveniently accessible DotDict object, filled with data.

class TheNounProjectAPI.models.CollectionsModel

Bases: TheNounProjectAPI.models.ModelList

CollectionsModel is a subclass of ModelList, which focuses on turning CollectionModel objects into a list. See Collections for more information regarding what attributes comes with this object.

classmethod parse(data, response=None)

Constructs and returns a list of CollectionModel objects. In addition, this list may have some additional attributes like generated_at based on the data dictionary.

class TheNounProjectAPI.models.IconModel

Bases: TheNounProjectAPI.models.Model

IconModel is a subclass of Model, with different attributes displayed when printed. See Icon for more information regarding what attributes comes with this object.

classmethod parse(data, response=None)

Constructs and returns an instance of (sub)class, with the json attribute set to a conveniently accessible DotDict object, filled with data.

class TheNounProjectAPI.models.IconsModel

Bases: TheNounProjectAPI.models.ModelList

IconsModel is a subclass of ModelList, which focuses on turning IconModel objects into a list. See Icons for more information regarding what attributes comes with this object.

classmethod parse(data, response=None)

Constructs and returns a list of IconModel objects. In addition, this list may have some additional attributes like generated_at based on the data dictionary.

class TheNounProjectAPI.models.UsageModel

Bases: TheNounProjectAPI.models.Model

UsageModel is a subclass of Model, with different attributes displayed when printed. See Usage for more information regarding what attributes comes with this object.

class TheNounProjectAPI.models.EnterpriseModel

Bases: TheNounProjectAPI.models.Model

EnterpriseModel is a subclass of Model, with different attributes displayed when printed. See Enterprise for more information regarding what attributes comes with this object.

class TheNounProjectAPI.models.OutputKeys(key, title=None)

Bases: object

Class to store key and title value, used for outputting attributes.

Constructs a ‘OutputKeys’ object, with a key and a title.

class TheNounProjectAPI.models.DotDict

Bases: dict

Subclass of dict allowing dot notation for items in the dict:

1
2
3
dot_dict.author.username 
# is equivalent to:
dot_dict["author"]["username"]
class TheNounProjectAPI.models.DotList

Bases: list

Subclass of list allowing dot notation for dicts that might be in the list.

TheNounProjectAPI.models.sequence_to_dot(val)

Returns DotDict of val if val is a dict. Returns DotList of val if val is a list. Otherwise returns val.

Return type

Any