For interacting with the Metrc API
Project description
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pymetrc-0.2.2.tar.gz
.
File metadata
- Download URL: pymetrc-0.2.2.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63d483893b863573aa77e3b065019def2b08a51249dcf14be41577fd8d84067e |
|
MD5 | 5d95d03dd25f36ef499ed422f22cc3e3 |
|
BLAKE2b-256 | cf9fa80b24b5fd8ae2b08cf3e957d21ded8556db59a8b6969dce3a7886e12bef |
File details
Details for the file pymetrc-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: pymetrc-0.2.2-py3-none-any.whl
- Upload date:
- Size: 23.7 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | afb62a4b9b80a164ec4ccbdc12f19cbd3af37ac0810970bae293ffdf4697c512 |
|
MD5 | 3db2c83783f70c68b61036a61bd7e872 |
|
BLAKE2b-256 | b548845bf0a865f6d9cba952ec9511d02f81bd15f3b430b0255cd6c8f7d0e29f |