Skip to main content

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

Project description

License: MIT | PyPi Package | PyPi Versions

Build Status | Test Coverage | Code Climate

Python Cannabis Reports

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

Installation

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 .

Usage

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

Connection

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')

API Endpoints

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.

Known Issues / Road Map

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

Credits

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

Maintainer

LasLabs Inc.

This module is maintained by LasLabs Inc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
cannabis-reports-0.1.1.tar.gz (138.7 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page