Skip to content

LasLabs/python-cannabis-reports

Repository files navigation

License: MIT | PyPi Package | PyPi Versions

Build Status | Test Coverage | Code Climate

This library allows you to interact with the Cannabis Reports API using Python.

Installation is easiest using Pip and PyPi:

pip install cannabis-reports

If you would like to contribute, or prefer Git:

git clone https://github.com/LasLabs/python-cannabis-reports.git
cd python-cannabis-reports
pip install .

The CannabisReports object is the primary point of interaction with the CannabisReports API.

Connecting to the CannabisReports API will require an API Key, which is generated from within your CannabisReports account. In the below example, our key is API_KEY.

from cannabis_reports import CannabisReports
cr = CannabisReports('API_KEY')

The CannabisReports API endpoints are exposed as variables on the instantiated CannabisReports object. The available endpoints are:

They can also be viewed from the __apis__ property of CannabisReports:

>>> cr.__apis__
{'Strains': <CannabisReports.auth_proxy.AuthProxy object at 0x10783ddd0>,
 }

API usage is as simple as calling the method with the required parameters and iterating the results:

for strain in cr.Strains.list():
    print(strain)
    print(strain.serialize())
    break

The output from the above would look something like the below:

# This is the Strain object itself (first print)
<cannabis-reports.models.strain.Strain object at 0x10783df10>
# This is the serialized form of the Strain (second print)
{'name': '#1K',
 'updated_at': {
     'datetime': '2015-06-16 22:10:20',
     'timezone': 'UTC'
 },
 'lineage': [],
 'qr': 'https://www.cannabisreports.com/strain-reports/unknown-breeder/1k/qr-code.svg',
 'seed_company': {
     '__class__': 'SeedCompany',
     'ucpc': '9XVU700000000000000000000',
     'link': 'https://www.cannabisreports.com/api/v1.0/seed-companies/9XVU700000000000000000000'
 },
 'genetics': {'__class__': 'StrainGenetics'},
 'created_at': {'datetime': '2015-06-16 22:10:20', 'timezone': 'UTC'},
 'reviews': {
     '__class__': 'GeneralOverview',
     'link': 'https://www.cannabisreports.com/api/v1.0/strains/9XVU7PZUEC000000000000000/reviews'
 },
 'image': 'https://www.cannabisreports.com/images/strains/no_image.png',
 'ucpc': '9XVU7PZUEC000000000000000',
 '__class__': 'Strain',
 'url': 'https://www.cannabisreports.com/strain-reports/unknown-breeder/1k',
 'children': {
     '__class__': 'GeneralOverview',
     'count': 2,
     'link': 'https://www.cannabisreports.com/api/v1.0/strains/9XVU7PZUEC000000000000000/children'
 },
 'link': 'https://www.cannabisreports.com/api/v1.0/strains/9XVU7PZUEC000000000000000'
}

In some instances, such as in the case of browsing for a record by its UCPC, a singleton is expected. In these instances, the singleton is directly used instead of iterated

>>> strain = cr.Strains.get('9XVU7PZUEC000000000000000')
>>> strain
<cannabis-reports.models.strain.Strain object at 0x101723e50>
>>> strain.serialize()
{'name': '#1K',
 'updated_at': {
     'datetime': '2015-06-16 22:10:20',
     'timezone': 'UTC'
 },
 'lineage': [],
 'qr': 'https://www.cannabisreports.com/strain-reports/unknown-breeder/1k/qr-code.svg',
 'seed_company': {
     '__class__': 'SeedCompany',
     'ucpc': '9XVU700000000000000000000',
     'link': 'https://www.cannabisreports.com/api/v1.0/seed-companies/9XVU700000000000000000000'
 },
 'genetics': {'__class__': 'StrainGenetics'},
 'created_at': {'datetime': '2015-06-16 22:10:20', 'timezone': 'UTC'},
 'reviews': {
     '__class__': 'GeneralOverview',
     'link': 'https://www.cannabisreports.com/api/v1.0/strains/9XVU7PZUEC000000000000000/reviews'
 },
 'image': 'https://www.cannabisreports.com/images/strains/no_image.png',
 'ucpc': '9XVU7PZUEC000000000000000',
 '__class__': 'Strain',
 'url': 'https://www.cannabisreports.com/strain-reports/unknown-breeder/1k',
 'children': {
     '__class__': 'GeneralOverview',
     'count': 2,
     'link': 'https://www.cannabisreports.com/api/v1.0/strains/9XVU7PZUEC000000000000000/children'
 },
 'link': 'https://www.cannabisreports.com/api/v1.0/strains/9XVU7PZUEC000000000000000'
}

Note that all of the API responses will be parsed, with proper objects being created from the results. The objects are all defined in the cannabis-reports.models package.

  • This ReadMe could use work
  • More testing on the endpoints. Kept getting rate limited and have not yet received and API key.

Most of the doc strings were taken directly from the Cannabis Reports API Documentation

LasLabs Inc.

This module is maintained by LasLabs Inc.