Skip to main content

PasteDB Python SDK

Project description

PasteDB Python SDK

Official Python SDK for PasteDB — FastAPI powered text and image sharing platform.

Installation

pip install pastedb

Authentication

Get your API key from PasteDB Dashboard → API Keys.

export PASTEDB_API_KEY="pdb_xxxxxxxxxxxx"

ME

● Me()

from pastedb import Client


client = Client(api_key="pdb_xxxxxxxxxxxxx")

print(client.me())

Response if API key is valid

{
'email': 'your@email.com',
'created_at': '2026-06-21T05:26:34.361000' # Dummy
}


Quick Start

from pastedb import Client

# Initialize client - reads PASTEDB_API_KEY env var or pass api_key
client = Client(api_key="pdb_xxxxxxxxxxxxx")

# Create a paste - pass data as dict
paste = client.create_paste({
    "content": "print('Hello from PasteDB!')",
    "title": "Hello World",
    "syntax": "python"
})

print(paste["id"])   # abc123

Core API Methods

The SDK methods mirror the FastAPI backend routes. All data is passed as dictionaries and responses are returned as dictionaries.

1. Create Paste

POST /pastes

from pastedb import Client
 "content": "Your text here",
    "title": "My Paste",
    "syntax": "javascript"
})

# Private paste with password
paste = client.create_paste({
    "content": "Secret data",
    "visibility": "private",
    "password": "mySecret123"
})

# Custom URL + expiry
paste = client.create_paste({
    "content": "Temporary data",
    "custom_id": "temp-data-2024",
    "expiration": "1d",
    "syntax": "json"
})

Request Body

Field Type Required Description
content str Yes Paste content
title str No Default: Untitled
syntax str No Default: text
visibility str No public or private, default public
password str No Password for private/public pastes
custom_id str No Custom slug for URL
expiration str No 1h, 1d, 7d, 30d, never

Response

{
  "id": "abc123",
  "title": "My Paste",
  "content": "Your text here",
  "syntax": "javascript",
  "visibility": "public",
  "created_at": "1781262330.906314"
}

OR

{
    'status': 'success',
    'id': '6a378ece819c1a9b62472339', 
    'custom_id': None
}

2. Get Paste

GET /pastes/{paste_id}

client = Client()

# Get by ID
paste = client.get_paste("abc123")

# Get by custom slug
paste = client.get_paste("my-custom-url")

# Get private paste - pass password in params
paste = client.get_paste("secret123", params={"password": "mySecret123"})

print(paste["title"])
print(paste["content"])

4. Update Paste

PATCH /pastes/{paste_id}

client = Client()
paste = client.update_paste("abc123", {
    "title": "Updated Title",
    "content": "New content here",
    "syntax": "markdown"
})

5. Delete Paste

DELETE /pastes/{paste_id}

client = Client()
client.delete_paste("abc123")

7. Get Analytics

GET /pastes/{paste_id}/analytics

client = Client()
stats = client.get_analytics("abc123")

print(stats["views"])           # 142
print(stats["unique_visitors"]) # 89

Error Handling

The SDK raises requests.HTTPError for API errors. Status codes match FastAPI:

from pastedb import Client
from requests import HTTPError

client = Client(api_key="pdb_live_xxx")

try:
    paste = client.get_paste("invalid-id")
except HTTPError as e:
    if e.response.status_code == 404:
        print("Paste not found")
    elif e.response.status_code == 401:
        print("Invalid API key")
    elif e.response.status_code == 403:
        print("Password required")
    else:
        print(f"API error: {e}")

Client Configuration

from pastedb import Client

client = Client(
    api_key="pdb_live_xxx",  # Optional, uses env var if None
    base_url="https://api.pastedb.netlify.app",  # Override default   
)

FastAPI Backend Reference

Your backend routes use these FastAPI dependencies:

from fastapi import FastAPI, HTTPException, Depends, Query, Cookie, Request, status, Response

The SDK handles auth via Authorization: Bearer <api_key> header or cookies.

Examples

CLI Upload

import sys
from pastedb import Client

client = Client()
content = sys.stdin.read()
paste = client.create_paste({"content": content, "title": "CLI Paste"})
print(paste["url"])

Usage: cat file.py | python paste.py

Supported Syntax

text, python, javascript, typescript, json, yaml, markdown, html, css, sql, bash, c, cpp, java, go, rust, php, ruby, swift, kotlin, and many more.

License

MIT License


Built with ❤️ using FastAPI

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

pastedb-1.0.17.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

pastedb-1.0.17-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file pastedb-1.0.17.tar.gz.

File metadata

  • Download URL: pastedb-1.0.17.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pastedb-1.0.17.tar.gz
Algorithm Hash digest
SHA256 2578777716991b1b229b59f41e0d73391c7b41264e44fe46457114e6cfc2c1cb
MD5 d9cbbf2b713419ce82673c3c1c26cdf8
BLAKE2b-256 72ec5c3ef9b2b090a7f92f7bf6f4700895e62fa3a7ebe76c922165e00ad43ad0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pastedb-1.0.17.tar.gz:

Publisher: publish.yml on sorathiya903/pastedb-package-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pastedb-1.0.17-py3-none-any.whl.

File metadata

  • Download URL: pastedb-1.0.17-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pastedb-1.0.17-py3-none-any.whl
Algorithm Hash digest
SHA256 19b00746f3587602dab7c29eee63868b3cd5c7c50142ad66fb70f98fa54d147a
MD5 058d339f1a3f08514f2e5129a06f4e30
BLAKE2b-256 5ff0d400260d2b1ab1e74fff0b7589c820cbd36285cbf4399a40330281fb6152

See more details on using hashes here.

Provenance

The following attestation bundles were made for pastedb-1.0.17-py3-none-any.whl:

Publisher: publish.yml on sorathiya903/pastedb-package-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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