cannabis_reports package

Subpackages

Submodules

cannabis_reports.auth_proxy module

class cannabis_reports.auth_proxy.AuthProxy(session, proxy_class)[source]

Bases: object

This object acts as a transparent authentication proxy for the API.

This is required because the API objects are naive of the authentication that is setup in CannabisReports, and all of the API interface methods are classmethods because they are instantiating.

METHOD_NO_PROXY = ['auth_proxy']
auth_proxy(method)[source]

Authentication proxy for API requests.

This is required because the API objects are naive of CannabisReports, so they would otherwise be unauthenticated.

Parameters:method (callable) – A method call that should be authenticated. It should accept a requests.Session as its first parameter, which should be used for the actual API call.
Returns:The results of the authenticated callable.
Return type:mixed

cannabis_reports.base_api module

class cannabis_reports.base_api.BaseApi[source]

Bases: object

This is the API interface object to be implemented by API adapters.

It acts as a collection for the API object that it represents, passing through iteration to the API’s request paginator.

BASE_URI

str – CannabisReports API URI base.

paginator

RequestPaginator – Object to use for producing an iterator representing multiple requests (API response pages). Created on init.

__object__

cannabis_reports.models.BaseModel – Model object that API represents.

BASE_URI = 'https://www.cannabisreports.com/api/v1.0'
classmethod get(session, ucpc)[source]

Gets an individual object based on the UCPC.

Parameters:
  • session (requests.sessions.Session) – Authenticated session.
  • ucpc (str) – UCPC for the cannabis object you want information about.
Returns:

The object that was found.

Return type:

cls.__object__

classmethod list(session, sort='created_at', descending=False, limit=None)[source]

Return all objects, with optional sorting.

Parameters:
  • session (requests.sessions.Session) – Authenticated session.
  • sort (str) –

    Column to sort by. One of:

    • created_at
    • updated_at
    • name
  • descending (bool, optional) – Set to True to put newest records at the top.
  • limit (int, optional) – Stop after iterating this many pages.
Returns:

Objects iterator.

Return type:

RequestPaginator(output_type=cls.__object__)

classmethod new_object(data)[source]

Return a new object of the correct type from the data.

Parameters:data (dict) – Data dictionary that should be converted to an object. It can use either camelCase keys or snake_case.
Returns:A model of the type declared in cls.__object__.
Return type:BaseModel
paginator = None

cannabis_reports.base_model module

class cannabis_reports.base_model.BaseModel(**kwargs)[source]

Bases: properties.base.base.HasProperties

This is the model that all other models inherit from.

It provides some convenience functions, and the standard id property.

Required Properties:

  • created_at (CustomDateTime): Localized date and time when this record was created., a datetime object
  • ucpc (String): UCPC code for this record., a unicode string
  • updated_at (CustomDateTime): Localized date and time when this record was modified., a datetime object
created_at

Localized date and time when this record was created.

classmethod from_api(**kwargs)[source]

Create a new instance from API arguments.

This will switch camelCase keys into snake_case for instantiation.

It will also identify any Instance or List properties, and instantiate the proper objects using the values. The end result being a fully Objectified and Pythonified API response.

Returns:Instantiated model using the API values.
Return type:BaseModel
get(key, default=None)[source]

Return the field indicated by the key, if present.

static get_non_empty_vals(mapping)[source]

Return the mapping without any None values.

to_api()[source]

Return a dictionary to send to the API.

Returns:
Mapping representing this object that can be sent to the
API.
Return type:dict
ucpc

UCPC code for this record.

updated_at

Localized date and time when this record was modified.

Bases: cannabis_reports.base_model.BaseModel

Required Properties:

  • created_at (CustomDateTime): Localized date and time when this record was created., a datetime object
  • link (String): Link to the record in the Cannabis Reports API., a unicode string
  • qr (String): Link to the QR code for this record., a unicode string
  • ucpc (String): UCPC code for this record., a unicode string
  • updated_at (CustomDateTime): Localized date and time when this record was modified., a datetime object
  • url (String): Link to the record listing on the Cannabis Reports website., a unicode string

Link to the record in the Cannabis Reports API.

qr

Link to the QR code for this record.

url

Link to the record listing on the Cannabis Reports website.

class cannabis_reports.base_model.CustomDateTime(doc, **kwargs)[source]

Bases: properties.basic.DateTime

Implementation of DateTime supporting the proper format:

Object containing two strings, “dateTime” and the “timezone” when the strain was added.

FORMAT_DT = '%Y-%m-%d %H:%M:%S'
static from_json(value, **kwargs)[source]
static to_json(value, **kwargs)[source]
class cannabis_reports.base_model.GeneralOverview(**kwargs)[source]

Bases: cannabis_reports.base_model.BaseModel

Object that holds a general overview of other objects.

This is the object that is typically returned by the API, which holds the high level information & how to access the actual dataset.

Required Properties:

  • count (Integer): Total amount of reviews for this record., an integer
  • created_at (CustomDateTime): Localized date and time when this record was created., a datetime object
  • link (String): Link to the detailed review information in the Cannabis Reports API., a unicode string
  • ucpc (String): UCPC code for this record., a unicode string
  • updated_at (CustomDateTime): Localized date and time when this record was modified., a datetime object
count

Total amount of reviews for this record.

Link to the detailed review information in the Cannabis Reports API.

class cannabis_reports.base_model.LineageModel(**kwargs)[source]

Bases: cannabis_reports.base_model.LinksModelWithImage

Required Properties:

  • created_at (CustomDateTime): Localized date and time when this record was created., a datetime object
  • image (String): Link to the full size image for this record on Cannabis Reports., a unicode string
  • lineage (Property): Countries of origin for the genetics for the strain. Object keys are the country name and the values are the two character country codes.
  • link (String): Link to the record in the Cannabis Reports API., a unicode string
  • qr (String): Link to the QR code for this record., a unicode string
  • ucpc (String): UCPC code for this record., a unicode string
  • updated_at (CustomDateTime): Localized date and time when this record was modified., a datetime object
  • url (String): Link to the record listing on the Cannabis Reports website., a unicode string
lineage

Countries of origin for the genetics for the strain. Object keys are the country name and the values are the two character country codes.

class cannabis_reports.base_model.LinksModelWithImage(**kwargs)[source]

Bases: cannabis_reports.base_model.BaseModelWithLinks

Required Properties:

  • created_at (CustomDateTime): Localized date and time when this record was created., a datetime object
  • image (String): Link to the full size image for this record on Cannabis Reports., a unicode string
  • link (String): Link to the record in the Cannabis Reports API., a unicode string
  • qr (String): Link to the QR code for this record., a unicode string
  • ucpc (String): UCPC code for this record., a unicode string
  • updated_at (CustomDateTime): Localized date and time when this record was modified., a datetime object
  • url (String): Link to the record listing on the Cannabis Reports website., a unicode string
image

Link to the full size image for this record on Cannabis Reports.

cannabis_reports.exceptions module

exception cannabis_reports.exceptions.CannabisReportsException(message)[source]

Bases: exceptions.Exception

Base exception for CannabisReports library errors.

exception cannabis_reports.exceptions.CannabisReportsRemoteException(status_code, message)[source]

Bases: cannabis_reports.exceptions.CannabisReportsException

Indicates that an error occurred when communicating with the remote.

exception cannabis_reports.exceptions.CannabisReportsSecurityException(message)[source]

Bases: cannabis_reports.exceptions.CannabisReportsException

Indicates a security error; probably by an invalid web hook signature.

exception cannabis_reports.exceptions.CannabisReportsValidationException(message)[source]

Bases: cannabis_reports.exceptions.CannabisReportsException

Indicates an error while validating user-supplied data.

Module contents

class cannabis_reports.AuthProxy(session, proxy_class)[source]

Bases: object

This object acts as a transparent authentication proxy for the API.

This is required because the API objects are naive of the authentication that is setup in CannabisReports, and all of the API interface methods are classmethods because they are instantiating.

METHOD_NO_PROXY = ['auth_proxy']
auth_proxy(method)[source]

Authentication proxy for API requests.

This is required because the API objects are naive of CannabisReports, so they would otherwise be unauthenticated.

Parameters:method (callable) – A method call that should be authenticated. It should accept a requests.Session as its first parameter, which should be used for the actual API call.
Returns:The results of the authenticated callable.
Return type:mixed
class cannabis_reports.BaseApi[source]

Bases: object

This is the API interface object to be implemented by API adapters.

It acts as a collection for the API object that it represents, passing through iteration to the API’s request paginator.

BASE_URI

str – CannabisReports API URI base.

paginator

RequestPaginator – Object to use for producing an iterator representing multiple requests (API response pages). Created on init.

__object__

cannabis_reports.models.BaseModel – Model object that API represents.

BASE_URI = 'https://www.cannabisreports.com/api/v1.0'
classmethod get(session, ucpc)[source]

Gets an individual object based on the UCPC.

Parameters:
  • session (requests.sessions.Session) – Authenticated session.
  • ucpc (str) –

    UCPC for the cannabis object you want information about.

Returns:

The object that was found.

Return type:

cls.__object__

classmethod list(session, sort='created_at', descending=False, limit=None)[source]

Return all objects, with optional sorting.

Parameters:
  • session (requests.sessions.Session) – Authenticated session.
  • sort (str) –

    Column to sort by. One of:

    • created_at
    • updated_at
    • name
  • descending (bool, optional) – Set to True to put newest records at the top.
  • limit (int, optional) – Stop after iterating this many pages.
Returns:

Objects iterator.

Return type:

RequestPaginator(output_type=cls.__object__)

classmethod new_object(data)[source]

Return a new object of the correct type from the data.

Parameters:data (dict) – Data dictionary that should be converted to an object. It can use either camelCase keys or snake_case.
Returns:A model of the type declared in cls.__object__.
Return type:BaseModel
paginator = None
class cannabis_reports.BaseModel(**kwargs)[source]

Bases: properties.base.base.HasProperties

This is the model that all other models inherit from.

It provides some convenience functions, and the standard id property.

Required Properties:

  • created_at (CustomDateTime): Localized date and time when this record was created., a datetime object
  • ucpc (String): UCPC code for this record., a unicode string
  • updated_at (CustomDateTime): Localized date and time when this record was modified., a datetime object
created_at

Localized date and time when this record was created.

classmethod from_api(**kwargs)[source]

Create a new instance from API arguments.

This will switch camelCase keys into snake_case for instantiation.

It will also identify any Instance or List properties, and instantiate the proper objects using the values. The end result being a fully Objectified and Pythonified API response.

Returns:Instantiated model using the API values.
Return type:BaseModel
get(key, default=None)[source]

Return the field indicated by the key, if present.

static get_non_empty_vals(mapping)[source]

Return the mapping without any None values.

to_api()[source]

Return a dictionary to send to the API.

Returns:
Mapping representing this object that can be sent to the
API.
Return type:dict
ucpc

UCPC code for this record.

updated_at

Localized date and time when this record was modified.

class cannabis_reports.CannabisReports(api_key=None)[source]

Bases: object

This object is the primary point of interaction with CannabisReports.

Properties will be set on this CannabisReports instance that will mirror the class names of APIs in the cannabis_reports.api module.

These API classes are naive of authentication, so the actual properties set will be using the AuthProxy class, which will transparently inject authentication into the API requests while still allowing for a naive API object.

This allows for the CannabisReports instance to act as a container for all of the authenticated API objects.

Examples:

from cannabis_reports import CannabisReports
cr = CannabisReports('api_key')
for strain in cr.Strains.list():
    print(strain.serialize())