Skip to main content

Official TurtleQR API client. Dynamic QR codes that keep working even after you stop paying.

Project description

turtleqr (Python)

Official Python client for the TurtleQR API.

TurtleQR makes dynamic QR codes that keep working even after you stop paying. This client is a thin, zero-dependency wrapper over the REST API (standard library only, Python 3.8+).

Install

pip install turtleqr

Quickstart

from turtleqr import TurtleQR

tq = TurtleQR(api_key="qr_live_...")

# Create a dynamic URL code (fields are the API's camelCase names)
code = tq.codes.create(type="url", targetUrl="https://example.com/launch", tags=["spring"])
print(code["shortUrl"])  # https://qr.turtleqr.com/AbC123xy

# Re-point it later without reprinting the QR
tq.codes.update(code["id"], targetUrl="https://example.com/sale")

# Analytics + raw image bytes
stats = tq.codes.analytics(code["id"], range="30d")
png = tq.codes.image(code["id"], format="png", size=1024)

Methods

Method Endpoint
codes.create(**fields) POST /v1/codes
codes.list(...) GET /v1/codes
codes.get(code_id) GET /v1/codes/:id
codes.update(code_id, **fields) PATCH /v1/codes/:id
codes.delete(code_id) DELETE /v1/codes/:id
codes.bulk_create(codes) POST /v1/codes/bulk (up to 50)
codes.scans(code_id, ...) GET /v1/codes/:id/scans
codes.analytics(code_id, ...) GET /v1/codes/:id/analytics
codes.image(code_id, ...) GET /v1/codes/:id/image
codes.conversions(code_id) GET /v1/codes/:id/conversions
conversions.create(**fields) POST /v1/conversions
webhooks.create / list / get / update / delete …/v1/webhooks
webhooks.test(id) / webhooks.deliveries(id) …/v1/webhooks/:id/test · /deliveries

Conversions, retargeting & webhooks

# Record a conversion (from your server, after a sale/signup), then read the rollup
tq.conversions.create(codeId="code_1", eventName="purchase", valueCents=2599, currency="USD")
summary = tq.codes.conversions("code_1")
print(summary["totals"]["conversions"])

# Hosted-page codes can fire the page owner's pixels via `tracking` at create time
tq.codes.create(
    type="business-page",
    businessPage={"name": "Ada Lovelace", "links": []},
    tracking={"metaPixelId": "123456789012", "googleTagId": "G-ABC1234"},
)

# Webhooks
hook = tq.webhooks.create(url="https://example.com/turtleqr", event_filter=["code.created"])
print(hook["signingSecret"])  # shown once — store it now
tq.webhooks.test(hook["id"])

Errors

Any non-2xx response raises TurtleQRError with status, code (e.g. slug_conflict), and detail:

from turtleqr import TurtleQRError

try:
    tq.codes.create(type="url", targetUrl="https://example.com", slug="taken")
except TurtleQRError as err:
    if err.code == "slug_conflict":
        ...  # pick another slug
    else:
        raise

Verifying incoming webhooks

from turtleqr import verify_webhook_signature

# Flask:
@app.route("/hook", methods=["POST"])
def webhook():
    ok = verify_webhook_signature(
        header=request.headers.get("Turtleqr-Signature", ""),
        body=request.get_data(as_text=True),   # read before json parsing
        secret=os.environ["TURTLEQR_WEBHOOK_SECRET"],
    )
    if not ok:
        abort(401)
    event = request.get_json()
    ...

Tests

Pure standard library, no test deps:

cd clients/python && python3 -m unittest discover -s tests -t .

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

turtleqr-0.1.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

turtleqr-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file turtleqr-0.1.0.tar.gz.

File metadata

  • Download URL: turtleqr-0.1.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for turtleqr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a58f0d84802e40249603a52f770ca151abff2f37c0e8dcfce39cb70e7bc860c9
MD5 74d8c144648e867faa870ae97451ac05
BLAKE2b-256 a0ffa56876fb9f6e270e1a78ac4e44e39d07767bc6e79146d92f2a955950df16

See more details on using hashes here.

File details

Details for the file turtleqr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: turtleqr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for turtleqr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 021669877e198f5f3a962dbd0f7947adec5314bf7322b4ee770ec55e0356035a
MD5 74868ca5fcb359ee6f242901fc858c19
BLAKE2b-256 cb99ea90e53338a87b24fe1e8aad8089bb94907494ee3e78e4e8e92e2b514cba

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