PasteConnect is a Python library for interacting with Pastebin. It allows you to check account validity, authenticate, create pastes, delete pastes, and retrieve raw paste content.
Python 3.7 or higher is required.
You can install PasteConnect using pip
:
+$ pip install pasteconnect
Install from source repository
+$ pip install git+https://github.com/heartlog/pasteconnect.git
To use PasteConnect, you need your Pastebin credentials, which include your username
, password
, and api_key
.
If you don't have these, you can obtain them by signing up for a Pastebin account and generating an api_key
from the Pastebin API documentation.
from pasteconnect import PasteConn
# Initialize a PasteConnect client
pastebin = PasteConn(username, password, api_key)
# Check account validity
account_status = pastebin.check_account()
print(account_status)
title = "My Paste Title"
content = "This is the content of my paste."
# Create a paste on Pastebin
paste_url = pastebin.create_paste(title, content, privacy=1)
print(f"Paste created: {paste_url}")
To interact with PasteConnect, you need to initialize a client with your credentials:
-required for other methods to work
Refer Getting Started
username = "your_username"
password = "your_password"
api_key = "your_api_key"
# Initialize the client
pastebin = PasteConn(username, password, api_key)
Alternatively, you can initialize with predefined environment variables
pastebin = PasteConn() # with pre define env var
You can check the validity of your Pastebin account using the following method:
result = pastebin.check_account()
print(result) # Response: '[heartlog] is Valid Account. User key : "user_key"'
To authenticate and get your user_key
, use the auth()
method:
Get user_key
using give credentials.
result = pastebin.auth()
print(result) # Response: "user_key"
You can create a paste on Pastebin with a title, content, and privacy level. Privacy levels can be 0 (public), 1 (unlisted), or 2 (private):
privacy = 1 # (default - private)
title = "Title of paste"
content = """
Hello
This is multiline text
"""
pastebin.create_paste(title, content, privacy=1)
To delete a paste, provide its URL or ID using the delete_paste(url)
method:
url = "https://pastebin.com/kZATAWhe"
result = pastebin.delete_paste(url)
print(result) # Response: "Paste Removed"
You can retrieve the raw content of a paste using it's URL or ID:
from pasteconnect import get_raw
result = get_raw(url)
print(result)
Alternatively, you can use the get_raw
function:
url = "https://pastebin.com/your_paste_id"
result = pastebin.get_raw_content(url)
print(result) # Response: "Content of paste"
Made with ❤️ by Heartlog
venaxyt for pastebinapi. Helped a lot in project. 😁