Skip to main content

A modern Python SDK for URL shortening service and more

Project description

SEE URL Python SDK

Python Version License Code style: black Type checked: mypy

A modern Python SDK for interacting with SEE URL shortening service, featuring async support, full type safety, and Python 3.11+ capabilities.

Features

  • 🚀 Modern Python: Built with Python 3.11+ features (type hints, pattern matching, dataclasses)
  • 🔄 Async First: Fully async API based on asyncio and httpx
  • 📝 Type Safe: 100% type annotated with mypy strict mode support
  • 🛡️ Reliable: Built-in retry mechanism, error handling, and rate limiting
  • 🧪 Well Tested: Comprehensive test suite with pytest
  • 📦 Standard Compliant: Follows PEP 517/518 with pyproject.toml

Requirements

  • Python 3.11+
  • httpx >= 0.27.0

Installation

pip install see-url-sdk

Install from source:

git clone https://github.com/yourusername/see-url-sdk.git
cd see-url-sdk
pip install -e .

Quick Start

Environment Setup

Use environment variables to store your API key:

Use environment variables to store your API key:

export SEE_API_KEY="your-api-key-here"

Basic Usage

import asyncio
import os
from see import SeeClient
from see.models import CreateShortUrlRequest

async def main():
    api_key = os.getenv("SEE_API_KEY")
    
    async with SeeClient(api_key=api_key) as client:
        request = CreateShortUrlRequest(
            domain="s.ee",
            target_url="https://example.com/very/long/url",
            title="Example Short URL"
        )
        
        response = await client.create_short_url(request)
        print(f"Code: {response.code}")
        print(f"Message: {response.message}")
        print(f"Data: {response.data}")

asyncio.run(main())

Custom Short URL

import os
from datetime import datetime, timedelta
from see import SeeClient
from see.models import CreateShortUrlRequest

api_key = os.getenv("SEE_API_KEY")

async with SeeClient(api_key=api_key) as client:
    expire_time = int((datetime.now() + timedelta(days=30)).timestamp())
    
    request = CreateShortUrlRequest(
        domain="s.ee",
        target_url="https://example.com/product/123",
        custom_slug="product123",
        title="Product 123",
        expire_at=expire_time,
        tag_ids=[1, 2]
    )
    
    response = await client.create_short_url(request)
    print(f"Custom URL: {response.data}")

Managing URLs

import os
from see import SeeClient
from see.models import UpdateShortUrlRequest, DeleteShortUrlRequest

api_key = os.getenv("SEE_API_KEY")

async with SeeClient(api_key=api_key) as client:
    update_request = UpdateShortUrlRequest(
        domain="s.ee",
        slug="abc123",
        target_url="https://example.com/new-destination",
        title="Updated Title"
    )
    updated = await client.update_short_url(update_request)
    
    delete_request = DeleteShortUrlRequest(
        domain="s.ee",
        slug="abc123"
    )
    deleted = await client.delete_short_url(delete_request)
    deleted = await client.delete_short_url(delete_request)

Domains and Tags

import os
from see import SeeClient

api_key = os.getenv("SEE_API_KEY")

async with SeeClient(api_key=api_key) as client:
    domains = await client.get_domains()
    print(f"Domains: {domains.data}")
    
    tags = await client.get_tags()
    print(f"Tags: {tags.data}")

Advanced Usage

Custom Configuration

import os
from see import SeeClient

api_key = os.getenv("SEE_API_KEY")

client = SeeClient(
    api_key=api_key,
    base_url="https://s.ee/api",
    timeout=60.0,
    max_retries=5,
    proxy=None
)

Error Handling

import os
from see import SeeClient
from see.models import CreateShortUrlRequest
from see.exceptions import (
    ValidationError,
    AuthenticationError,
    RateLimitError,
    NotFoundError,
    APIError
)

api_key = os.getenv("SEE_API_KEY")

async with SeeClient(api_key=api_key) as client:
    try:
        request = CreateShortUrlRequest(
            domain="s.ee",
            target_url="https://example.com",
            title="Example"
        )
        response = await client.create_short_url(request)
    except ValidationError as e:
        print(f"Validation error: {e}")
    except AuthenticationError as e:
        print(f"Authentication failed: {e}")
    except RateLimitError as e:
        print(f"Rate limit: {e}")
    except NotFoundError as e:
        print(f"Not found: {e}")
    except APIError as e:
        print(f"API error: {e}")

Development

Setup

git clone https://github.com/yourusername/see-url-sdk.git
cd see-url-sdk

python -m venv venv
source venv/bin/activate  # Linux/macOS

pip install -e ".[dev]"
pre-commit install

Testing

pytest
pytest --cov=see_url --cov-report=html
pytest tests/test_client.py

Code Quality

black src/ tests/
ruff check src/ tests/
mypy src/

API Reference

SeeClient

Main client class for API interactions.

Methods

  • create_short_url(request) - Create short URL
  • update_short_url(request) - Update short URL
  • delete_short_url(request) - Delete short URL
  • get_domains() - Get available domains
  • get_tags() - Get available tags

Models

CreateShortUrlRequest

@dataclass
class CreateShortUrlRequest:
    domain: str
    target_url: str
    title: str
    custom_slug: str | None = None
    expire_at: int | None = None
    tag_ids: list[int] | None = None

Exceptions

  • SeeError - Base exception
  • APIError - API error
  • AuthenticationError - Authentication error
  • ValidationError - Validation error
  • RateLimitError - Rate limit error
  • NotFoundError - Not found error

Contributing

Contributions are welcome! See CONTRIBUTING.md for details.

License

MIT License - see LICENSE file.

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

see_sdk-0.1.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

see_sdk-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for see_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7f26e579b038a85ff772fb95668c41d4ea4112bc122728c2143bceb465c0fb27
MD5 b65fbb33f7ede7afcbbf60995ca8bb65
BLAKE2b-256 3e74584ca1a6c807635032bfaaaa9f2483c725a89f6e93df30aeee62f56b5428

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for see_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 538499c875cc2872f77d60dfb1538f8ee00d9ae954b0a74cfd5cc40789371d5d
MD5 8137f062b759bf1c51c0ce219aa7e1ae
BLAKE2b-256 2b94e2f754b948e9b700b7f43b2741cea12b5f0c00fa5f39901612207998a53d

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