Skip to content

Client

Metrc Client | Cannlytics

This module contains the Client class responsible for communicating with the Metrc API.

Client

An instance of this class communicates with the Metrc API.

__init__(self, vendor_api_key, user_api_key, primary_license='', state='ok', test=False) special

Initialize a Metrc API client.

Parameters:

Name Type Description Default
vendor_api_key str

Required Metrc API key, obtained from Metrc upon successful certification. The vendor API key is the software provider's secret used in every instance, regardless of location or licensee.

required
user_api_key str

Required user secret obtained from a licensee's Metrc user interface. The user's permissions determine the level of access to the Metrc API.

required
primary_license str

A license to use if no license is provided on individual requests.

''
state str

The state of the licensee, Oklahoma (ok) by default.

'ok'

Examples:

track = metrc.Client(
    vendor_api_key='abc',
    user_api_key='xyz',
    primary_license='123',
    state='ok'
)

change_package_items(self, data, license_number='')

Update package items.

Parameters:

Name Type Description Default
data list

A list of package items (dict) to update.

required
license_number str

A specific license number.

''

create_harvest_packages(self, data, license_number='')

Create packages from a harvest.

Parameters:

Name Type Description Default
data list

A list of packages (dict) to create.

required
license_number str

A specific license number.

''

create_harvest_testing_packages(self, data, license_number='')

Create packages from a harvest for testing.

Parameters:

Name Type Description Default
data list

A list of testing packages (dict) to create.

required
license_number str

A specific license number.

''

create_items(self, data, license_number='')

Create items.

Parameters:

Name Type Description Default
data list

A list of items (dict) to create.

required
license_number str

A specific license number.

''

create_locations(self, data, license_number='')

Create location(s).

Parameters:

Name Type Description Default
data list

A list of locations (dict) to create.

required
license_number str

Optional license number filter.

''

create_packages(self, data, license_number='', qa=False, plantings=False)

Create packages.

Parameters:

Name Type Description Default
data list

A list of packages (dict) to create.

required
license_number str

A specific license number.

''
qa bool

If the packages are for QA testing.

False
plantings bool

If the packages are for planting.

False

create_patients(self, data, license_number='')

Create patient(s).

Parameters:

Name Type Description Default
data list

A list of patient (dict) to add.

required

create_receipts(self, data, license_number='')

Create receipt(s).

Parameters:

Name Type Description Default
data list

A list of receipts (dict) to create.

required
license_number str

A specific license number.

''

create_strains(self, data, license_number='')

Create strain(s).

Parameters:

Name Type Description Default
data list

A list of strains (dict) to create.

required
license_number str

A specific license number.

''

create_transactions(self, data, date, license_number='')

Create transaction(s).

Parameters:

Name Type Description Default
data list

A list of transactions (dict) to create.

required
date str

An ISO 8601 formatted string of the transaction date.

required
license_number str

A specific license number.

''

create_transfer_templates(self, data, license_number='')

Create transfer_template(s).

Parameters:

Name Type Description Default
data list

A list of transfer templates (dict) to create.

required

create_transfers(self, data, license_number='')

Create transfer(s).

Parameters:

Name Type Description Default
data list

A list of transfers (dict) to create.

required
license_number str

A specific license number.

''

delete_item(self, uid, license_number='')

Delete item.

Parameters:

Name Type Description Default
uid str

The UID of an item to delete.

required
license_number str

A specific license number.

''

delete_location(self, uid, license_number='')

Delete location.

Parameters:

Name Type Description Default
uid str

The UID of a location to delete.

required
license_number str

Optional license number filter.

''

delete_package(self, uid, license_number='')

Delete a package.

Parameters:

Name Type Description Default
uid str

The UID of a package to delete.

required
license_number str

A specific license number.

''

delete_patient(self, uid, license_number='')

Delete patient.

Parameters:

Name Type Description Default
uid str

The UID of a patient to delete.

required

delete_receipt(self, uid, license_number='')

Delete receipt.

Parameters:

Name Type Description Default
uid str

The UID of a receipt to delete.

required
license_number str

A specific license number.

''

delete_strain(self, uid, license_number='')

Delete strain.

Parameters:

Name Type Description Default
uid str

The UID of a strain to delete.

required
license_number str

A specific license number.

''

delete_transfer(self, uid, license_number='')

Delete transfer.

Parameters:

Name Type Description Default
uid str

The UID of a transfer to delete.

required
license_number str

A specific license number.

''

delete_transfer_template(self, uid, license_number='')

Delete transfer template.

Parameters:

Name Type Description Default
uid str

The UID of a transfer template to delete.

required

finish_harvests(self, data, license_number='')

Finish harvests.

Parameters:

Name Type Description Default
data list

A list of harvests (dict) to finish.

required
license_number str

A specific license number.

''

get_analyses(self, license_number='')

Get required quality assurance analyses.

Parameters:

Name Type Description Default
license_number str

A specific license number.

''

get_batches(self, uid='', action='active', license_number='', start='', end='')

Get plant batches(s).

Parameters:

Name Type Description Default
uid str

The UID for a plant batch.

''
action str

The action to apply to the plants, with options: active, inactive, types

'active'
license_number str

A specific license number.

''
start str

An ISO 8601 formatted string to restrict the start by the last modified time.

''
end str

An ISO 8601 formatted string to restrict the end by the last modified time.

''

get_customer_types(self, license_number='')

Get all facilities.

Parameters:

Name Type Description Default
license_number str

A specific license number.

''

get_employees(self, license_number='')

Get all employees.

Parameters:

Name Type Description Default
license_number str

A licensee's license number.

''

get_facilities(self)

Get all facilities.

get_harvests(self, uid='', action='active', license_number='', start='', end='')

Get harvests.

Parameters:

Name Type Description Default
uid str

The UID of a harvest, takes precedent over action.

''
action str

A specific filter to apply, including: active, onhold, inactive, waste/types.

'active'
license_number str

The licensee's license number.

''
start str

An ISO 8601 formatted string to restrict the start by the last modified time.

''
end str

An ISO 8601 formatted string to restrict the end by the last modified time.

''

get_item_categories(self, license_number='')

Get all item categories.

Parameters:

Name Type Description Default
license_number str

A specific license number.

''

get_items(self, uid='', action='active', license_number='')

Get items.

Parameters:

Name Type Description Default
uid str

The UID of an item.

''
action str

A specific type of item to filter by: active, categories, brands.

'active'
license_number str

A specific license number.

''

get_lab_results(self, uid='', license_number='')

Get lab results.

Parameters:

Name Type Description Default
uid str

The UID for a package.

''
license_number str

A specific license number.

''

get_lab_statuses(self, license_number='')

Get pre-defined lab statuses.

Parameters:

Name Type Description Default
license_number str

A specific license number.

''

get_locations(self, uid='', action='active', license_number='')

Get locations.

Parameters:

Name Type Description Default
uid str

The UID of a location, takes precedent over action.

''
action str

A specific filter to apply, with options: active, types.

'active'
license_number str

A specific license number.

''

get_package_statuses(self, license_number='')

Get all package status choices.

Parameters:

Name Type Description Default
license_number str

A specific license number.

''

get_package_types(self, license_number='')

Get all facilities.

Parameters:

Name Type Description Default
license_number str

A specific license number.

''

get_packages(self, uid='', label='', action='active', license_number='', start='', end='')

Get package(s).

Parameters:

Name Type Description Default
uid str

The UID for a package.

''
label str

The tag label for a package.

''
license_number str

A specific license number.

''
action str

active, onhold, inactive, types, adjust/reasons,

'active'
start str

Optional ISO date to restrict earliest modified transfers.

''
end str

Optional ISO date to restrict latest modified transfers.

''

get_patients(self, uid='', action='active', license_number='')

Get licensee member patients.

Parameters:

Name Type Description Default
uid str

A UID for a patient.

''
action str

An optional filter to apply: active.

'active'
license_number str

A licensee's license number to filter by.

''

get_plants(self, uid='', label='', action='', license_number='', start='', end='')

Get plant(s).

Parameters:

Name Type Description Default
uid str

The UID for a plant.

''
label str

The label for a given plant.

''
action str

A specific filter to apply, with options: vegetative, flowering, onhold, inactive, additives, additives/types, growthphases, waste/methods, waste/reasons.

''
license_number str

A specific license number.

''
start str

An ISO 8601 formatted string to restrict the start by the last modified time.

''
end str

An ISO 8601 formatted string to restrict the end by the last modified time.

''

get_receipts(self, uid='', action='active', license_number='', start='', end='', sales_start='', sales_end='')

Get sale(s).

Parameters:

Name Type Description Default
uid str

The UID for a plant batch.

''
action str

The action to apply to the plants, with options: active or inactive

'active'
license_number str

A specific license number.

''
start str

An ISO 8601 formatted string to restrict the start by the last modified time.

''
end str

An ISO 8601 formatted string to restrict the end by the last modified time.

''
sales_start str

An ISO 8601 formatted string to restrict the start by the sales time.

''
sales_end str

An ISO 8601 formatted string to restrict the end by the sales time.

''

get_strains(self, uid='', action='active', license_number='')

Get strains.

Parameters:

Name Type Description Default
uid str

A UID for a strain.

''
action str

An optional filter to apply: active.

'active'
license_number str

A licensee's license number to filter by.

''

get_transactions(self, license_number='', start='', end='')

Get transaction(s).

Parameters:

Name Type Description Default
license_number str

A specific license number.

''
start str

An ISO 8601 formatted string to restrict the start by the sales time.

''
end str

An ISO 8601 formatted string to restrict the end by the sales time.

''

get_transfer_packages(self, uid, license_number='', action='packages')

Get shipments.

Parameters:

Name Type Description Default
uid str

Required UID of a shipment.

required
license_number str

A specific license number.

''
action str

The filter to apply to transfers: packages, packages/wholesale, requiredlabtestbatches.

'packages'

get_transfer_templates(self, uid='', action='', license_number='', start='', end='')

Get transfer template(s).

Parameters:

Name Type Description Default
uid str

A UID for a transfer template.

''
action str

An optional filter to apply: deliveries, packages.

''
license_number str

A specific license number.

''
start str

An ISO 8601 formatted string to restrict the start by the sales time.

''
end str

An ISO 8601 formatted string to restrict the end by the sales time.

''

get_transfer_types(self, license_number='')

Get all transfer types.

Parameters:

Name Type Description Default
license_number str

A specific license number.

''

get_transfers(self, uid='', transfer_type='incoming', license_number='', start='', end='')

Get transfers.

Parameters:

Name Type Description Default
uid str

The UID for a transfer, takes precedent in query.

''
transfer_type str

The type of transfer: incoming, outgoing, or rejected.

'incoming'
license_number str

A specific license number.

''
start str

Optional ISO date to restrict earliest modified transfers.

''
end str

Optional ISO date to restrict latest modified transfers.

''

get_transporter_details(self, uid)

Get the details of the transporter driver and vehicle.

Parameters:

Name Type Description Default
uid str

The ID of the shipment delivery.

required

get_transporters(self, uid)

Get the data for a transporter.

Parameters:

Name Type Description Default
uid str

The ID of the shipment delivery.

required

get_uom(self, license_number='')

Get all units of measurement.

manage_batches(self, data, action, license_number='', from_mother=False)

Manage plant batch(es) by applying a given action.

Parameters:

Name Type Description Default
data list

A list of plants (dict) to manage.

required
action str

The action to apply to the plants, with options: createplantings, createpackages, split, /create/packages/frommotherplant, changegrowthphase, additives, destroy.

required
from_mother bool

An optional parameter for the createpackages action.

False

manage_packages(self, data, action='adjust', license_number='')

Adjust package(s).

Parameters:

Name Type Description Default
data list

A list of packages (dict) to manage.

required
license_number str

A specific license number.

''
action str

The action to apply to the packages, with options: adjust, finish, unfinish, remediate.

'adjust'

manage_plants(self, data, action, license_number='')

Manage plant(s) by applying a given action.

Parameters:

Name Type Description Default
data list

A list of plants (dict) to manage.

required
action str

The action to apply to the plants, with options: moveplants, changegrowthphases, destroyplants, additives, additives/bylocation, create/plantings, create/plantbatch/packages, manicureplants, harvestplants.

required
license_number str

A specific license number.

''

move_batch(self, data, license_number='')

Move plant batch(es).

Parameters:

Name Type Description Default
data list

A list of plant batches (dict) to move.

required

move_harvests(self, data, license_number='')

Move a harvests.

Parameters:

Name Type Description Default
data list

A list of harvests (dict) to move.

required
license_number str

A specific license number.

''

post_lab_results(self, data, license_number='')

Post lab result(s).

Parameters:

Name Type Description Default
data list

A list of lab results (dict) to create or update.

required
license_number str

A specific license number.

''

release_lab_results(self, data, license_number='')

Release lab result(s).

Parameters:

Name Type Description Default
data list

A list of package labels (dict) to release lab results.

required
license_number str

A specific license number.

''

remove_waste(self, data, license_number='')

Remove's waste from a harvest.

Parameters:

Name Type Description Default
data list

A list of waste (dict) to unfinish.

required
license_number str

A specific license number.

''

request(self, method, endpoint, data=None, params=None, verbose=True)

Make a request to the Metrc API.

unfinish_harvests(self, data, license_number='')

Unfinish harvests.

Parameters:

Name Type Description Default
data list

A list of harvests (dict) to unfinish.

required
license_number str

A specific license number.

''

update_items(self, data, license_number='')

Update items.

Parameters:

Name Type Description Default
data list

A list of items (dict) to update.

required
license_number str

A specific license number.

''

update_locations(self, data, license_number='')

Update location(s).

Parameters:

Name Type Description Default
data list

A list of locations (dict) to update.

required
license_number str

Optional license number filter.

''

update_package_item_locations(self, data, license_number='')

Update package item location(s).

Parameters:

Name Type Description Default
data list

A list of package items (dict) to move.

required
license_number str

A specific license number.

''

update_package_note(self, data, license_number='')

Update package note(s).

Parameters:

Name Type Description Default
data list

A list of package notes (dict) to update.

required
license_number str

A specific license number.

''

update_packages(self, data, license_number='')

Update packages

Parameters:

Name Type Description Default
data list

A list of packages (dict) to update.

required
license_number str

A specific license number.

''

update_patients(self, data, license_number='')

Update strain(s).

Parameters:

Name Type Description Default
data list

A list of patients (dict) to update.

required

update_receipts(self, data, license_number='')

Update receipt(s).

Parameters:

Name Type Description Default
data list

A list of receipts (dict) to update.

required
license_number str

A specific license number.

''

update_strains(self, data, license_number='')

Update strain(s).

Parameters:

Name Type Description Default
data list

A list of strains (dict) to update.

required
license_number str

A specific license number.

''

update_transactions(self, data, date, license_number='')

Update transaction(s).

Parameters:

Name Type Description Default
data list

A list of transactions (dict) to update.

required
date str

An ISO 8601 formatted string of the transaction date.

required
license_number str

A specific license number.

''

update_transfer_templates(self, data, license_number='')

Update transfer template(s).

Parameters:

Name Type Description Default
data list

A list of transfer templates (dict) to update.

required

update_transfers(self, data, license_number='')

Update transfer(s).

Parameters:

Name Type Description Default
data list

A list of transfers (dict) to update.

required
license_number str

A specific license number.

''

upload_coas(self, data, license_number='')

Upload lab result CoA(s).

Parameters:

Name Type Description Default
data list

A list of CoAs (dict) to upload.

required
license_number str

A specific license number.

''