Skip to main content

Pymetrc

Only the Montana endpoints are tested at this time. Each state dictates the subset of features Metrc exposes. As such, this may not work as intended with other state API endpoints.

This project is intended to provide abstraction and easy integration with the Metrc REST API. It provides easily digestible output for use with Pandas and data analysis, storage, etc.

AIOHTTP is used to make concurrent calls to the API as the time-based query limitations can make necessary many individual GET requests, especially when initializing a database with all packages, sales receipts, etc.

Currently, only GET endpoints are implemented. Once these are covered, POST and PUT functionality is planned.

Installation

Pymetrc is available via pip:

pip install pymetrc

Usage

Upon instantiation of a Metrc object, an initial GET request is made to populate the facility list stored by the object. These facilities are those the given user has access to. This does not currently guarantee that the given user has permission to access the endpoints specified -- this is planned for future implementations.

Date/time strings passed must be in ISO 8601 format.

It is ill-advised to use API keys directly in code. It is recommended to use environment variables or other more secure means to store your API credentials:

import os

vendor_api_key = os.environ['METRC_VENDOR_API_KEY']
user_api_key = os.environ['METRC_USER_API_KEY']

Employees

from pymetrc import Metrc

state = 'mt'
m = Metrc(vendor_api_key, user_api_key, state)

data = m.get_basic("employees_v1")

Packages

from pymetrc import Metrc

state = 'mt'
m = Metrc(vendor_api_key, user_api_key, state)

data = m.get_last_modified("packages_v1_active", "D-12345", "2020-01-01T00:00:00+00:00", "2021-01-01T00:00:00+00:00")

This returns a list of dictionary objects, each representing an entity of the type requested. In the above example, we get back a list of packages.

Sales Transactions

from pymetrc import Metrc

state = 'mt'
m = Metrc(vendor_api_key, user_api_key, state)

data = m.get_sales_transactions("D-12345", "2020-01-01T00:00:00+00:00", "2021-01-01T00:00:00+00:00")

In the above example, we get a list of receipts each containing a sub-list of per-package transactions. Requesting sales transactions via Pymetrc prompts a request first for the sales receipts in this time period. The receipt ids are parsed and then the sales transactions can be queried using these ids. Sales receipts can be requested if only high-level sales information is needed.

Technologies

Release files for pymetrc 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymetrc 0.2.2
File Size Uploaded
pymetrc-0.2.2.tar.gz 23.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymetrc 0.2.2
File Interpreter ABI Platform
pymetrc-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 47.7 kB

Release files / pymetrc-0.2.2.tar.gz

Download URL pymetrc-0.2.2.tar.gz
Size 23.9 kB
Tags Source
SHA-256 checksum
How to use checksums
63d483893b863573aa77e3b065019def2b08a51249dcf14be41577fd8d84067e
BLAKE2b-256 checksum
How to use checksums
cf9fa80b24b5fd8ae2b08cf3e957d21ded8556db59a8b6969dce3a7886e12bef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

Release files / pymetrc-0.2.2-py3-none-any.whl

Download URL pymetrc-0.2.2-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
afb62a4b9b80a164ec4ccbdc12f19cbd3af37ac0810970bae293ffdf4697c512
BLAKE2b-256 checksum
How to use checksums
b548845bf0a865f6d9cba952ec9511d02f81bd15f3b430b0255cd6c8f7d0e29f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page