Quick Start
For quick, single interactions with PrivateBin, use the top-level convenience functions:
They offer a convenient way to quickly interact with PrivateBin
without setting up a PrivateBin
client.
Each function automatically creates a temporary client for its operation and then releases it.
Because they create a new client each time, these functions are less efficient and performant
if you are performing many operations in a row against the same PrivateBin instance.
For more complex workflows, or when you need direct control over network requests
(for example, to configure timeouts, proxies, or custom headers), it is more efficient
and flexible to create and reuse a PrivateBin
client instance directly.
get
get(
url: str | PrivateBinUrl, *, password: str | None = None
) -> Paste
Retrieve and decrypt a paste from a PrivateBin URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str | PrivateBinUrl
|
The complete URL of the PrivateBin paste. |
required |
password
|
str
|
Password to decrypt the paste if it was created with one. |
None
|
Returns:
Type | Description |
---|---|
Paste
|
A |
Raises:
Type | Description |
---|---|
PrivateBinError
|
If there is an error retrieving or decrypting the paste from the server. |
ValueError
|
If the provided URL string is not in the expected format. |
TypeError
|
If the provided |
Examples:
import privatebin
paste = privatebin.get("https://privatebin.net/?pasteid#passphrase")
print(paste.text)
For password-protected pastes:
import privatebin
paste = privatebin.get("https://privatebin.net/?pasteid#passphrase", password="pastepassword")
print(paste.text)
Source code in src/privatebin/_wrapper.py
create
create(
text: str,
*,
server: str | PrivateBinUrl = "https://privatebin.net/",
attachment: Attachment | None = None,
password: str | None = None,
burn_after_reading: bool = False,
open_discussion: bool = False,
expiration: Expiration = ONE_WEEK,
formatter: Formatter = PLAIN_TEXT,
compression: Compression = ZLIB,
) -> PrivateBinUrl
Create a new paste on PrivateBin.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The text content of the paste. |
required |
server
|
str | PrivateBinUrl
|
The base URL of the PrivateBin instance to use. |
'https://privatebin.net/'
|
attachment
|
Attachment
|
An attachment to include with the paste. |
None
|
password
|
str
|
A password to encrypt the paste with an additional layer of security. If provided, users will need this password in addition to the passphrase to decrypt the paste. |
None
|
burn_after_reading
|
bool
|
Set to |
False
|
open_discussion
|
bool
|
Set to |
False
|
expiration
|
Expiration
|
The desired expiration time for the paste. |
ONE_WEEK
|
formatter
|
Formatter
|
The formatting option for the paste content. |
PLAIN_TEXT
|
compression
|
Compression
|
The compression algorithm to use for the paste data. |
ZLIB
|
Returns:
Type | Description |
---|---|
PrivateBinUrl
|
A |
Raises:
Type | Description |
---|---|
PrivateBinError
|
|
TypeError
|
If the provided |
Examples:
Create a simple paste on the default PrivateBin instance:
Create a paste on a custom PrivateBin server with Markdown formatting and burn-after-reading:
import privatebin
from privatebin import Formatter
md_paste_url = privatebin.create(
text="# Markdown Content\n\nThis is **markdown** formatted text.",
server="https://myprivatebin.example.org/",
formatter=Formatter.MARKDOWN,
burn_after_reading=True
)
print(f"Markdown paste URL: {md_paste_url}")
Create a password-protected paste with an attachment:
import privatebin
from privatebin import Attachment
attachment = Attachment.from_file("path/to/your/file.txt")
password_paste_url = privatebin.create(
text="This paste has a password and an attachment.",
password="supersecret",
attachment=attachment
)
print(f"Password-protected paste URL: {password_paste_url}")
Source code in src/privatebin/_wrapper.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
delete
delete(
url: str | PrivateBinUrl, *, delete_token: str
) -> None
Delete a paste from PrivateBin using its URL and delete token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str | PrivateBinUrl
|
The complete URL of the PrivateBin paste, with or without the passphrase. |
required |
delete_token
|
str
|
The delete token associated with the paste. |
required |
Raises:
Type | Description |
---|---|
PrivateBinError
|
If there is an error deleting the paste on PrivateBin. |
ValueError
|
If the provided URL string is not in the expected format. |
TypeError
|
If the provided |
Examples:
import privatebin
paste_url = privatebin.create(text="This paste will be deleted.")
privatebin.delete(paste_url, delete_token=paste_url.delete_token)
print(f"Paste with URL '{delete_url}' deleted.")