PasteDB Python SDK

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(
    "your_api_key_here"
)

# 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.create_paste()

POST /pastes

Creates a new paste using a Python dictionary. 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()

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 → 10 minutes
1h → 1 hour
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.update_paste()

PATCH /pastes/{paste_id}
python
client.update_paste(
    "abc123",
    {
        "title":"Updated Title",
        "content":"New content here",
        "syntax":"markdown"
    }
)

Client.delete_paste()

DELETE /pastes/{paste_id}
python
client.delete_paste("abc123")

Client Configuration

python
from pastedb import Client

client = Client(
    api_key="pdb_live_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