Type-safe wrapper for ThunkMetrc Python client
Project description
ThunkMetrc Python Wrapper
Type-safe, rate-limited, async wrapper for the Metrc API.
📦 Installation
pip install thunkmetrc-wrapper
pip install thunkmetrc-client
🚀 Getting Started
1. Initialize
Use MetrcFactory to handle shared rate limiting effectively.
import asyncio
from thunkmetrc.wrapper import MetrcFactory
async def main():
# 1. Create Factory
# Shared RateLimiter (150 requests/sec integrator limit)
factory = MetrcFactory(max_concurrent_requests=150)
# 2. Create Wrapper for specific license
metrc = factory.create(
base_url="https://sandbox-api-or.metrc.com",
vendor_key="vendor_key",
user_key="user_key"
)
# ...
2. Make Requests
All service methods are async.
try:
facilities = await metrc.facilities.get_facilities()
for f in facilities:
print(f"Facility: {f.License.Number}")
except Exception as e:
print(f"Error: {e}")
3. Pagination (Async Iterator)
Use the iterate_ methods to stream pages comfortably.
async for pkg in metrc.packages.iterate_get_active_packages(
license_number="123-ABC-LICENSE"
):
print(f"Package: {pkg.Label}")
if __name__ == "__main__":
asyncio.run(main())
🛡️ Rate Limiting
The SDK uses MetrcRateLimiter to enforce:
- Integrator Limits: Default 150/sec.
- Facility Limits: Default 50/sec per facility.
- Backoff: Exponential backoff on 429/500 errors.
- Retries: Automatic retry logic.
Configuration is handled via MetrcFactory.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file thunkmetrc_wrapper-0.3.1.tar.gz.
File metadata
- Download URL: thunkmetrc_wrapper-0.3.1.tar.gz
- Upload date:
- Size: 57.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eba9bdf72ffa417955ebcd8afc440df342366e23fb0036751545771a38ac7769
|
|
| MD5 |
80c46fb11f3cf6ce0394a3b2dd88d071
|
|
| BLAKE2b-256 |
4c03eb907b636697e70b9a41d26bfd978b07810e24468a10543e4e03bd360c86
|
File details
Details for the file thunkmetrc_wrapper-0.3.1-py3-none-any.whl.
File metadata
- Download URL: thunkmetrc_wrapper-0.3.1-py3-none-any.whl
- Upload date:
- Size: 285.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
606f95a8460e9f7f7e14a3f843df052c512ebb505d03179b0477b56a0bf1e621
|
|
| MD5 |
0a07325386498169afc279a828d3da2b
|
|
| BLAKE2b-256 |
c92dedb76428c9140f60e0027a2015c8d11f7854e9071645563c7071fa31a89d
|