PasteDB Python SDK

Official Python SDK for interacting with the PasteDB API. Create pastes, manage your account, and automate workflows directly from Python. View on GitHub

Python SDK • FastAPI Powered • Secure API Keys

Installation

Install the SDK using pip:

bash
pip install pastedb

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" }

Methods

Current supported SDK methods:

python
cl.me()

cl.makePaste(
    title="Hello",
    content="My first paste",
    syntax="python",
    visibility="public"
)

Client.me()

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

GET /api/me
python
import pastedb as p

cl = p.Client(
    "your_api_key"
)

user = cl.me()

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

If the API key is invalid:

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

Client.makePaste()

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
makePaste(data: dict)

Example usage:

python
import pastedb as p

cl = p.Client(
    "your_api_key"
)

paste = cl.makePaste({

    "title": "Hello World",

    "content": "My first paste",

    "syntax": "python",

    "visibility": "public"
})

print(paste)
{ "status": "success", "id": "682dxxxxxxxx", "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" }

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