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
Installation
Install the SDK using pip:
pip install pastedb
Quick Start
Create your first paste in seconds.
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.
import pastedb as p
# initialize client
cl = p.Client(
"pdb_xxxxxxxxxxxxx"
)
# 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())
Client.me()
Returns information about the currently authenticated user. This method internally sends a GET request to:
from pastedb import Client
client = Client(
api_key="pdb_xxxxxxxxxxxxx"
)
print(client.me())
If the API key is invalid:
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.
The method accepts a single dictionary containing the paste details.
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)
Supported Fields
{
"title": "Paste title",
"content": "Paste content",
"syntax": "python",
"visibility": "public",
"custom_id": "optional-id",
"expiration": "1h",
"password": "optional-password"
}
Difference from create_paste()
Invalid API Key
Client.create_paste()
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:
The method accepts a single parameter:
create_paste(data: dict)
Example usage:
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"
})
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
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
Client.get_paste()
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:
from pastedb import Client
client = Client(
api_key="pdb_xxxxxxxxxxxxx"
)
pastes = client.api_user_pastes()
print(pastes)
This method is useful for listing, managing, updating, or deleting your existing pastes.
Invalid API Key
Client.api_update_paste()
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()
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
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.
import pastedb as p
try:
cl = p.Client("invalid_key")
print(cl.me())
except Exception as e:
print(e)