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
Installation
Install the SDK using pip:
pip install pastedb
Basic Usage
Initialize the client with your API key and make requests easily.
import pastedb as p
# initialize client
cl = p.Client(
"your_api_key_here"
)
# get account info
account = cl.me()
print(account)
Authentication
Every request requires a valid API key. Invalid or expired keys will return an HTTP 401 error.
import pastedb as p
cl = p.Client("invalid_key")
print(cl.me())
Methods
Current supported SDK methods:
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:
import pastedb as p
cl = p.Client(
"your_api_key"
)
user = cl.me()
print(user)
If the API key is invalid:
Client.makePaste()
Creates a new paste using a Python dictionary. This method internally sends a POST request to:
The method accepts a single parameter:
makePaste(data: dict)
Example usage:
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)
Supported Fields
{
"title": "Paste title",
"content": "Paste content",
"syntax": "python",
"visibility": "public",
"custom_id": "optional-id",
"expiration": "1h",
"password": "optional-password"
}
Visibility Options
Expiration Options
1h → 1 hour
never → no expiration
Invalid API Key
Error Handling
You can safely catch exceptions using try/except blocks.
import pastedb as p
try:
cl = p.Client("invalid_key")
print(cl.me())
except Exception as e:
print(e)