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.18.tar.gz (4.6 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.18-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pastedb-1.0.18.tar.gz
  • Upload date:
  • Size: 4.6 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.18.tar.gz
Algorithm Hash digest
SHA256 43ffbd77c5a8ff4200d1f4b0ed497cccd7173b58c0299869acbcf3e2409f65d2
MD5 a948d44798847e11101e1c976dbfaec5
BLAKE2b-256 0979adfb0868082aa1fbf37fed18d4346ddfbd8576427998f52510d7c5700554

See more details on using hashes here.

Provenance

The following attestation bundles were made for pastedb-1.0.18.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.18-py3-none-any.whl.

File metadata

  • Download URL: pastedb-1.0.18-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.18-py3-none-any.whl
Algorithm Hash digest
SHA256 70150a970cd524aa856ea94db87161284daa092f3d705ea161c94deb53e0d7a1
MD5 25e6142eeadca2560128d905079bf5da
BLAKE2b-256 6300483ff45a298a8cada0037d61aa5de8b5f3e19c1f46d7b0203008dd8dff65

See more details on using hashes here.

Provenance

The following attestation bundles were made for pastedb-1.0.18-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