Skip to main content

PasteDB Python SDK

Project description

PasteDB Python SDK

Official Python SDK for interacting with the PasteDB API.

Supports:

  • Create and manage pastes
  • Explore public pastes
  • Semantic vector search
  • Star system
  • Markdown rendering
  • Code execution
  • API key management
  • Analytics

Installation


pip install pastedb


Quick Start

import pastedb

client = PasteDBClient(
    api_key="YOUR_API_KEY"
)

paste = client.create_paste(
    title="Hello World",
    content="print('Hello')",
    syntax="python"
)

print(paste)

Initialize Client

from client import PasteDBClient

client = PasteDBClient(
    api_key="YOUR_API_KEY"
)

Parameters

Parameter| Type| Description api_key| str| Your PasteDB API key base_url| str| Custom API URL


Paste Methods

create_paste()

Create a new paste.

paste = client.create_paste(
    title="Example",
    content="print('Hello')",
    syntax="python"
)

Parameters

Parameter| Type| Default| Description title| str| Required| Paste title content| str| Required| Paste content syntax| str| plaintext| Syntax language visibility| str| public| public/private/unlisted expiration| str| never| Expiration time password| str| None| Password protection tags| list| []| Tags list


get_paste()

Get a paste by ID.

paste = client.get_paste("abc123")

edit_paste()

Edit an existing paste.

client.edit_paste(
    "abc123",
    title="Updated Title"
)

You can update:

  • title
  • content
  • syntax
  • visibility
  • tags
  • expiration

delete_paste()

Delete a paste.

client.delete_paste("abc123")

fork_paste()

Create a copy of an existing paste.

forked = client.fork_paste("abc123")

raw()

Get raw paste text.

raw = client.raw("abc123")

print(raw)

Search Methods

search()

Search public pastes.

results = client.search(
    query="fastapi auth",
    syntax="python"
)

Parameters

Parameter| Type| Description query| str| Search query syntax| str| Filter by language user| str| Filter by user tags| list| Filter by tags


vector_search()

Semantic vector search powered by MongoDB Vector Search.

results = client.vector_search(
    "dark animated navbar"
)

Finds similar pastes by meaning instead of exact keywords.


Explore Methods

explore()

Get explore page pastes.

pastes = client.explore()

trending()

Get trending pastes.

trending = client.trending()

latest()

Get latest public pastes.

latest = client.latest()

popular()

Get most popular pastes.

popular = client.popular()


Star Methods

star()

Toggle star on a paste.

client.star("abc123")

If already starred, it removes the star.


Analytics Methods

paste_stats()

Get analytics for a paste.

stats = client.paste_stats("abc123")

Example response:

{
    "views": 120,
    "copies": 30,
    "shares": 12,
    "stars": 9
}

User Methods

me()

Get current authenticated user.

user = client.me()

user_pastes()

Get public pastes from a user.

pastes = client.user_pastes("aditya")

user_starred()

Get starred pastes from a user.

starred = client.user_starred("aditya")

Code Runner Methods

run()

Execute code.

result = client.run(
    language="python",
    code="print('Hello')"
)

supported_languages()

Get supported execution languages.

languages = client.supported_languages()

Markdown Methods

render_markdown()

Render markdown into HTML.

html = client.render_markdown(
    "# Hello World"
)

API Key Methods

create_api_key()

Create API key.

key = client.create_api_key(
    "My Application"
)

get_api_keys()

Get all API keys.

keys = client.get_api_keys()

delete_api_key()

Delete API key.

client.delete_api_key("key123")

Error Handling

The SDK raises "PasteDBError" when requests fail.

from client import PasteDBClient, PasteDBError

try:

    client = PasteDBClient(
        api_key="INVALID"
    )

    client.me()

except PasteDBError as e:

    print(e)

Example Project

from client import PasteDBClient

client = PasteDBClient(
    api_key="YOUR_API_KEY"
)

paste = client.create_paste(
    title="Quick Sort",
    content="print('Sorting')",
    syntax="python",
    tags=["algorithm", "python"]
)

print("Created:", paste)

stats = client.paste_stats(
    paste["id"]
)

print(stats)

Features

  • Clean Python API
  • Easy authentication
  • Semantic search
  • Code execution
  • Collections support
  • Markdown rendering
  • Analytics support
  • API key management
  • Fast integration

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pastedb-1.0.13.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pastedb-1.0.13-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pastedb-1.0.13.tar.gz.

File metadata

  • Download URL: pastedb-1.0.13.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pastedb-1.0.13.tar.gz
Algorithm Hash digest
SHA256 772b2d0f6f17c7f43d6b94ef564cf9b45dcaa1b8402309335d189b25eb56a622
MD5 3286a95221816c02ec878ebc24ec02be
BLAKE2b-256 783f60e870c82c311089256678633304d6a177cdcecccc78c62092bcd23c48b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pastedb-1.0.13.tar.gz:

Publisher: publish.yml on sorathiya903/pastedb-package-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pastedb-1.0.13-py3-none-any.whl.

File metadata

  • Download URL: pastedb-1.0.13-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pastedb-1.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 3580f94a8f4554f4d2fa5dd5e596d444ac10614ba3fdb4560349f110c962bea6
MD5 2a8b42029ae9de8674220f13376dba3c
BLAKE2b-256 638e3dd6b55758caac5462c2a513899d2b516d2831c739f10fae09610639f3ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for pastedb-1.0.13-py3-none-any.whl:

Publisher: publish.yml on sorathiya903/pastedb-package-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page