Official PasteDB Python SDK documentation - Create, manage and automate pastes using the PasteDB API.

PasteDB Python SDK Documentation

Official Python SDK for PasteDB — a FastAPI powered text, code and image sharing platform. Create, retrieve, update and manage pastes directly from Python using a simple developer-friendly API. View on GitHub

Python SDK • FastAPI Powered • Secure API Keys

Installation

Install the SDK using pip:

bash
pip install pastedb

Quick Start

Create your first paste in seconds.

python
from pastedb import Client

client = Client(
    api_key="pdb_xxxxxxxxxxxxx"
)

paste = client.create_paste({
    "content": "print('Hello from PasteDB!')",
    "title": "Hello World",
    "syntax": "python"
})

print(paste["id"])

Basic Usage

Initialize the client with your API key and make requests easily.

python
import pastedb as p

# initialize client
cl = p.Client(
    "pdb_xxxxxxxxxxxxx"
)

# get account info
account = cl.me()

print(account)
{ "email": "your@email.com" }

Authentication

Every request requires a valid API key. Invalid or expired keys will return an HTTP 401 error.

python
import pastedb as p

cl = p.Client("invalid_key")

print(cl.me())
HTTP 401 Unauthorized { "detail": "Invalid API key" }

Client.me()

Returns information about the currently authenticated user. This method internally sends a GET request to:

GET /api/me
python
  from pastedb import Client

client = Client(
    api_key="pdb_xxxxxxxxxxxxx"
)

print(client.me())
{ "email":"your@email.com", "created_at":"2026-06-21T05:26:34.361000" }

If the API key is invalid:

HTTP 401 Unauthorized { "detail": "Invalid API key" }

Client.api_create_paste()

Creates a new paste using your API key. The created paste is linked to your account, allowing you to edit, delete, and manage it later from your dashboard or using other SDK methods.

POST /api/create

The method accepts a single dictionary containing the paste details.

python
from pastedb import Client

client = Client(
    api_key="pdb_xxxxxxxxxxxxx"
)

paste = client.api_create_paste({
    "title": "Hello API",
    "content": "print('Hello World')",
    "syntax": "python",
    "visibility": "public",
    "expiration": "1h"
})

print(paste)
{ "status": "success", "id": "6a378ece819c1a9b62472339", "custom_id": null }

Supported Fields

dict structure
{
  "title": "Paste title",

  "content": "Paste content",

  "syntax": "python",

  "visibility": "public",

  "custom_id": "optional-id",

  "expiration": "1h",

  "password": "optional-password"
}

Difference from create_paste()

create_paste() • Does NOT require an API key. • Creates a guest paste. • Paste is not linked to an account. api_create_paste() • Requires a valid API key. • Paste is owned by your account. • Can later be listed, updated and deleted using: - api_user_pastes() - api_update_paste() - api_delete_paste()

Invalid API Key

HTTP 401 Unauthorized { "detail": "Invalid API key" }

Client.create_paste()

POST /pastes

Creates a new guest paste using a Python dictionary. Doesn't uses api key, also if provided. To make pastes by api keys use api_create_paste(). This method internally sends a POST request to:

POST /api/create

The method accepts a single parameter:

python
create_paste(data: dict)

Example usage:

python
from pastedb import Client

client = Client() #No api key required for create_paste 

paste = client.create_paste({
    "content":"Hello World",
    "title":"My Paste",
    "syntax":"python"
})
{ "status":"success", "id":"6a378ece819c1a9b62472339", "custom_id":null }

Supported Fields

dict structure
{
  "title": "Paste title",

  "content": "Paste content",

  "syntax": "python",

  "visibility": "public",

  "custom_id": "optional-id",

  "expiration": "1h",

  "password": "optional-password"
}

Visibility Options

public → anyone can access private → only owner can access

Expiration Options

10m → Paste expires after 10 minutes.
30m → Paste expires after 30 minutes.
1h → Paste expires after 1 hour.
6h → Paste expires after 6 hours.
12h → Paste expires after 12 hours.
1d → Paste expires after 1 day.
3d → Paste expires after 3 days.
1w → Paste expires after 1 week.
30d → Paste expires after 30 days.
burn → Burn After Read – the paste is permanently deleted immediately after it is opened. never → no expiration

Invalid API Key

HTTP 401 Unauthorized { "detail": "Invalid API key" }

Client.get_paste()

GET /pastes/{paste_id}
python
paste = client.get_paste("abc123")

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

Client.api_user_pastes()

Returns all pastes owned by the authenticated API key. This method sends a GET request to:

GET /api/pastes
python
from pastedb import Client

client = Client(
    api_key="pdb_xxxxxxxxxxxxx"
)

pastes = client.api_user_pastes()

print(pastes)
{ "count": 2, "results": [ { "_id": "6856abc123456789abcdef12", "title": "My First Paste", "custom_id": "api", "syntax": "python", "visibility": "public" }, { "_id": "6856abc123456789abcdef34", "title": "Documentation", "custom_id": "docs", "syntax": "markdown", "visibility": "public" } ] }

This method is useful for listing, managing, updating, or deleting your existing pastes.

Invalid API Key

HTTP 401 Unauthorized { "detail": "Invalid API key" }

Client.api_update_paste()

PATCH /pastes/{paste_id}
python
client.api_update_paste(
    "6a37bd.......9d978c9f", # No custom IDs, only the id provided by Default. Get that id by api_user_pastes method
    {
        "title":"Updated Title",
        "content":"New content here",
        "syntax":"markdown"
    }
)

Client.api_delete_paste()

DELETE /pastes/{paste_id}
python
client.api_delete_paste("6a39u2e......r37479f")
# No custom IDs, only the id provided by Default. Get that id by api_user_pastes method
    

Client Configuration

python
from pastedb import Client

client = Client(
    api_key="pdb_xxx",
    base_url="https://api.pastedb.netlify.app"
)

Supported Syntaxes


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

Error Handling

You can safely catch exceptions using try/except blocks.

python
import pastedb as p

try:

    cl = p.Client("invalid_key")

    print(cl.me())

except Exception as e:

    print(e)
Copied to clipboard