Skip to main content

Mokkari

PyPI - Version PyPI - Python Ruff Pre-Commit

A python wrapper for the Metron Comic Book Database API.

Installation

pip install mokkari

Authentication

Mokkari supports two authentication methods:

import mokkari

# Token authentication (generate a token from your metron.cloud account page)
m = mokkari.api(api_token="your-api-token")

# Username/password (Basic Auth)
m = mokkari.api(username, password)

Example Usage

import mokkari

# Your own config file to keep your credentials secret
from config import username, password

m = mokkari.api(username, password)

# Get all Marvel comics for the week of 2021-06-07
this_week = m.issues_list(
    {
        "store_date_range_after": "2021-06-07",
        "store_date_range_before": "2021-06-13",
        "publisher_name": "marvel",
    }
)

# Print the results
for i in this_week:
    print(f"{i.id} {i.issue_name}")

    # Retrieve the detail for an individual issue
    asm_68 = m.issue(31660)

# Print the issue Description
print(asm_68.desc)

Rate Limiting

The API has a fixed limit of 20 requests per minute, plus a daily limit that starts at 5,000 requests and is raised for OpenCollective donors (up to 25,000/day). Because the daily limit varies per user, mokkari doesn't hardcode it — it reads the X-RateLimit-* headers Metron returns with every response and pre-empts a request once those headers show a window is exhausted, avoiding an HTTP call that would fail anyway. When a rate limit is exceeded, a RateLimitError is raised.

The most recently observed state is available via session.rate_limit_status:

status = m.rate_limit_status
print(f"Sustained remaining: {status.sustained.remaining}/{status.sustained.limit}")

Handling Rate Limits

The RateLimitError includes a retry_after attribute that tells you exactly how many seconds to wait before making another request:

import mokkari
from mokkari.exceptions import RateLimitError
import time

m = mokkari.api(username, password)

try:
    issue = m.issue(31660)
except RateLimitError as e:
    # Display user-friendly message
    print(f"Rate limited: {e}")

    # Programmatically wait for the exact time needed
    print(f"Waiting {e.retry_after} seconds...")
    time.sleep(e.retry_after)

    # Retry the request
    issue = m.issue(31660)

Thread Safety

A Session can be shared across threads, but the rate-limit check above is advisory rather than a hard gate: it only blocks once the last known response headers show a window is exhausted, and that check isn't synchronized with sending the request. Concurrent threads can therefore each pass the check and send their requests before either response updates rate_limit_status, letting a burst of threads momentarily exceed the per-minute limit (Metron's server-side limit still applies and will reject the excess requests).

If you're calling a shared Session from multiple threads, cap your own concurrency instead of relying on Session to do it for you, e.g. keep a ThreadPoolExecutor at or below the burst limit:

from concurrent.futures import ThreadPoolExecutor

m = mokkari.api(username, password)

# Keep worker count at or below the burst limit (20/min) to avoid racing
# past the local rate-limit check.
with ThreadPoolExecutor(max_workers=20) as executor:
    issues = list(executor.map(m.issue, issue_ids))

Documentation

Read the project documentation

Bugs/Requests

Please use the GitHub issue tracker to submit bugs or request features.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mokkari-4.4.0.tar.gz (79.6 kB view details)

Uploaded Source

Built Distribution

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

mokkari-4.4.0-py3-none-any.whl (59.7 kB view details)

Uploaded Python 3

File details

Details for the file mokkari-4.4.0.tar.gz.

File metadata

  • Download URL: mokkari-4.4.0.tar.gz
  • Upload date:
  • Size: 79.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.33 {"installer":{"name":"uv","version":"0.11.33","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mokkari-4.4.0.tar.gz
Algorithm Hash digest
SHA256 f3454f2eb54eb7029143877e9f1b4602c94e9e6ec63f75aec3785f393a84c6d5
MD5 d75a28ebf7829b0ba7a94c4a9fba217d
BLAKE2b-256 e7829bbbb7951a881ad7ac6f9442c73d240c232a7533696123b635e2cd93926d

See more details on using hashes here.

File details

Details for the file mokkari-4.4.0-py3-none-any.whl.

File metadata

  • Download URL: mokkari-4.4.0-py3-none-any.whl
  • Upload date:
  • Size: 59.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.33 {"installer":{"name":"uv","version":"0.11.33","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mokkari-4.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da2cefedd46ebc473ae2a6109c8ef4173196d7af424dcb6dfe4de1601e21384c
MD5 827c3d17f63757ab58a882e8d1b6225b
BLAKE2b-256 163a5edb310abe19998ff6b83491ca8582fd121b5cba8fc56410e237dcdbfbea

See more details on using hashes here.

Release history Release notifications | RSS feed

4.6.0

2 files

4.5.0

2 files

This release

4.4.0 This release

2 files

4.3.0

2 files

4.2.0

2 files

4.1.0

2 files

4.0.1

2 files

4.0.0

2 files

3.29.1

2 files

3.29.0

2 files

3.28.0

2 files

3.27.0

2 files

3.26.0

2 files

3.25.4

2 files

3.25.3

2 files

3.25.2

2 files

3.25.1

2 files

3.25.0

2 files

3.24.0

2 files

3.23.0

2 files

3.22.0

2 files

3.21.0

2 files

3.20.0

2 files

3.19.0

2 files

3.18.0

2 files

3.17.0

2 files

3.16.2

2 files

3.16.1

2 files

3.16.0

2 files

3.15.1

2 files

3.15.0

2 files

3.14.0

2 files

3.13.1

2 files

3.13.0

2 files

3.12.0

2 files

3.11.0

2 files

3.10.1

2 files

3.10.0

2 files

3.9.0

2 files

3.8.1

2 files

3.8.0

2 files

3.7.0

2 files

3.6.0

2 files

3.5.0

2 files

3.4.0

2 files

3.3.0

2 files

3.2.0

2 files

3.1.0

2 files

3.0.1

2 files

3.0.0

2 files

2.6.0

2 files

2.5.0

2 files

2.4.0

2 files

2.3.3

2 files

2.3.2

2 files

2.3.1

2 files

2.3.0

2 files

2.2.2

2 files

2.2.0

2 files

2.1.1

2 files

2.1.0

2 files

2.0.4

2 files

2.0.3

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

1.0.5

2 files

1.0.4

2 files

1.0.2

2 files

1.0.0

2 files

0.2.4

2 files

0.2.2

2 files

0.2.0

1 file

0.1.10

1 file

0.1.8

1 file

0.1.6

1 file

0.1.4

1 file

0.1.2

1 file

0.1.0

1 file

0.0.4

1 file

0.0.1

1 file

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