Skip to main content

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

thunkmetrc_wrapper-0.3.3.tar.gz (64.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thunkmetrc_wrapper-0.3.3-py3-none-any.whl (286.2 kB view details)

Uploaded Python 3

File details

Details for the file thunkmetrc_wrapper-0.3.3.tar.gz.

File metadata

  • Download URL: thunkmetrc_wrapper-0.3.3.tar.gz
  • Upload date:
  • Size: 64.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for thunkmetrc_wrapper-0.3.3.tar.gz
Algorithm Hash digest
SHA256 92045f5e11978a8c230dcd5f995f7b819b21129cf8c784b15b1d884c1d8efb85
MD5 d0d20434a82afe6f777d4e1a2d5f0578
BLAKE2b-256 86616fbdc4d9ddcfde6c436ed5b62e3dd0434103acd0dcd58bb7613f3d198e8d

See more details on using hashes here.

File details

Details for the file thunkmetrc_wrapper-0.3.3-py3-none-any.whl.

File metadata

File hashes

Hashes for thunkmetrc_wrapper-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1b8ed45ea13b9f7aaaf1b5b728e2846a079e3278f10f9f413adc47e583af8850
MD5 8ce572e09fcf575161d17e5f1db3fa9b
BLAKE2b-256 a97f499e0245736893487200f2baab328a3751567b6aca51dccb606f685327a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page