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.0.tar.gz (57.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.0-py3-none-any.whl (285.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: thunkmetrc_wrapper-0.3.0.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

Hashes for thunkmetrc_wrapper-0.3.0.tar.gz
Algorithm Hash digest
SHA256 69b90e78a6f376751f3a0b314193952d5bfd12639dbaa3464ccbe7b417d33b40
MD5 6342209cfa73b7728eb7a882808866e4
BLAKE2b-256 81bf9ccfa724609047e59c9903ef45c2cfb8050c79461dfd61795cd413560f7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thunkmetrc_wrapper-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 709f1ab476877811f354ca3949a1726495eb59ef1c2e018a8b90db41a396b0cf
MD5 6c6f4a9d8ce6fb2f3dc9f18028fe239c
BLAKE2b-256 d1b5e74238afbce02ea484da380e4042e8def8290232a752e75d7c859bbb37e7

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