Python integration guide

    How to generate short links and QR codes from Python

    Use Python to call the 1get API, create short links, and receive QR metadata in the same response for jobs, scripts, internal tools, and automation services.

    6 min
    Updated 2026-04-07
    Python + QR API
    Python requests
    QR in response
    Scoped keys
    Retry-safe writes
    Quick briefing
    SSR guide page
    Primary route

    POST /api/v1/links/shorten

    Client library

    requests or httpx

    Best fit

    Internal tools, queue jobs, reporting scripts, backend services

    Usage visibility

    GET /api/v1/usage for current billing window

    Python is a strong fit for background jobs, admin tooling, and automation services that need reliable short-link creation without browser sessions. The 1get external API is designed for exactly that machine-to-machine path.

    The first production pattern is simple: create a scoped key in the dashboard, store it in your secret manager, call the shorten endpoint, and consume the returned short URL plus QR metadata in one response.

    Authentication

    Keep the key server-side and treat the request as a machine workflow

    The Python caller should never need to choose an organization or send browser cookies. A scoped API key already resolves organization ownership, allowed scopes, and plan entitlements.

    • Prefer Authorization: Bearer <api_key>.
    • Use a fresh Idempotency-Key for each new write attempt.
    • Handle non-2xx responses as structured contract failures, not generic transport errors.
    Implementation

    Send one request and use the QR metadata immediately

    For most backend tasks, the shorten response gives you everything you need: the short URL, link id, and QR code object for later download or display.

    • A successful shorten-plus-QR flow counts as one API call.
    • If the same idempotency key is reused with a different payload, the API returns a conflict instead of silently creating a second record.
    Python requests example

    This pattern works well in cron jobs, Celery workers, FastAPI services, and internal tooling.

    python
    import os
    import uuid
    import requests
    
    payload = {
        "original_url": "https://acme.ai/reports/q2-launch",
        "custom_slug": "q2-launch",
        "qr": {"include": True, "format": "PNG", "size": 256},
    }
    
    response = requests.post(
        "https://1get.site/api/v1/links/shorten",
        headers={
            "Authorization": f"Bearer {os.environ['ONEGET_API_KEY']}",
            "Content-Type": "application/json",
            "Idempotency-Key": str(uuid.uuid4()),
        },
        json=payload,
        timeout=15,
    )
    
    response.raise_for_status()
    data = response.json()["data"]
    
    print(data["short_url"])
    print(data["qr_code"]["url"])
    Operations

    Pair the write lane with usage visibility and sane retry rules

    Python jobs often run in batches or retry automatically. Make the API contract part of that operating model instead of treating it like a fire-and-forget request.

    Read GET /api/v1/usage when your worker needs to understand the current window, remaining allowance, or active key count. That gives operations teams a cleaner view than guessing from task failures later.

    • Retry only when you have a transport failure or clear retryable status.
    • Use idempotency keys whenever the same task can be replayed.
    • Move to Business when multiple services or larger batch patterns share the same API lane.
    Related guides

    Keep the intent cluster connected.

    These follow-up guides cover adjacent implementation paths so searchers and evaluators can move deeper without losing context.