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
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(
"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())
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.create_paste()
Creates a new paste using a Python dictionary. 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()
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
1h → 1 hour
never → no expiration
Invalid API Key
Client.get_paste()
paste = client.get_paste("abc123")
print(paste["title"])
print(paste["content"])
Client.update_paste()
client.update_paste(
"abc123",
{
"title":"Updated Title",
"content":"New content here",
"syntax":"markdown"
}
)
Client.delete_paste()
client.delete_paste("abc123")
Client Configuration
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.
import pastedb as p
try:
cl = p.Client("invalid_key")
print(cl.me())
except Exception as e:
print(e)