PrivateBin API is a wrapper for API interactions with PrivateBin instances. It allows you to send, get, and delete pastes from PrivateBin instances.
PrivateBin API is available on PyPI:
$ python -m pip install privatebinapi
PrivateBin API officially supports Python 3.6+.
- Send, retrieve, and delete pastes on any PrivateBin instance
- Officially supports PrivateBin 1.0 through 1.3
- Full support for both synchronous and asynchronous code
- Upload and download files
- Proxy support
PrivateBin API is designed to be as easy to use as possible. A quick example of the most basic features is shown below:
>>> import privatebinapi
>>> send_response = privatebinapi.send("https://vim.cx", text="Hello, world!")
>>> get_response = privatebinapi.get(send_response["full_url"])
>>> get_response['text'] == "Hello, world!"
True
>>> delete_response = privatebinapi.delete(send_response["full_url"], send_response["deletetoken"])
Each function returns a modified version of the JSON received from the PrivateBin instance.
All parameters shown in the docs below are optional and may be combined in any way.
To send a paste containing nothing but text, do the following:
>>> import privatebinapi
>>> response = privatebinapi.send("https://vim.cx", text="Hello, world!")
You can expect the send function to return something similar to the following:
{
"deletetoken": "< paste delete token >",
"full_url": "< direct link to paste> ",
"id": "< paste ID >",
"passcode": "< paste passcode >",
"status": 0,
"url": "/?< paste ID >"
}
There are a limited number of valid expiration times. You must select one of the following:
("5min", "10min", "1hour", "1day", "1week", "1month", "1year", "never")
The default is "1day"
.
>>> import privatebinapi
>>> response = privatebinapi.send(
... "https://vim.cx",
... text="Hello, world!",
... expiration="5min"
... )
Putting a password on your paste is easy:
>>> import privatebinapi
>>> response = privatebinapi.send(
... "https://vim.cx",
... text="Hello, world!",
... password="Secure123!"
... )
There are only two valid options for this parameter: "zlib"
and
None
. The default is "zlib"
.
>>> import privatebinapi
>>> response = privatebinapi.send(
... "https://vim.cx",
... text="Hello, world!",
... compression=None
... )
There are only three valid options for this parameter: "plaintext"
,
"syntaxhighlighting"
, and "markdown"
. The default is
"plaintext"
.
>>> import privatebinapi
>>> response = privatebinapi.send(
... "https://vim.cx",
... text="Hello, world!",
... formatting="markdown"
... )
If you want a paste to be deleted immediately after being read, pass
True
to the burn_after_reading parameter. The default is
False
.
>>> import privatebinapi
>>> response = privatebinapi.send(
... "https://vim.cx",
... text="Hello, world!",
... burn_after_reading=True
... )
To enable discussion, pass True
to the discussion parameter. The
default is False
.
>>> import privatebinapi
>>> response = privatebinapi.send(
... "https://vim.cx",
... text="Hello, world!",
... discussion=True
... )
Getting a paste from a PrivateBin instance is very easy:
>>> import privatebinapi
>>> response = privatebinapi.get("https://example.com/?fakePasteLink#1234567890")
You can expect the get function to return something similar to the following:
{
"attachment": {
"content": b"< attachment content in bytes >",
"filename": "< name of attachment >"
},
"id": '< paste ID >",
"meta": {
"created": < UNIX timestamp >,
"time_to_live": < seconds until deletion >
},
"status": 0,
"text": "< text content of the paste >",
"url": "/?< paste ID >",
"v": < encryption version 1 or 2 >}
}
If the paste is password protected, use the password parameter.
>>> import privatebinapi
>>> response = privatebinapi.get(
... "https://example.com/?fakePasteLink#1234567890",
... password="Secure123!"
... )
You can expect the delete function to return something similar to the following:
{
"id": '< paste ID >",
"status": 0,
"url": "/?< paste ID >",
}
To delete a paste, you need its URL and delete token.
>>> import privatebinapi
>>> response = privatebinapi.delete(
... "https://example.com/?fakePasteLink#1234567890",
... "fake1delete2token3"
... )
All functions have an optional keyword parameter, proxies, that accepts a dictionary of proxies like you would see in the Requests package.
>>> import privatebinapi
>>> response = privatebinapi.send(
... "https://vim.cx",
... text="Hello, world!",
... proxies={
... "http": "http://example.com/proxy:80",
... "https": "https://example.com/proxy:8080"
... }
... )
privatebinapi.send
, privatebinapi.get
and
privatebinapi.delete
all have async analogs. They accept all the
same parameters that their synchronous counterparts do.
import asyncio
import privatebinapi
async def main():
send_response = await privatebinapi.send_async(
"https://vim.cx",
text="Hello, world!"
)
get_response = await privatebinapi.get_async(send_response["full_url"])
delete_response = await privatebinapi.delete_async(
send_response["full_url"],
send_response["deletetoken"]
)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Both privatebinapi.send
and privatebinapi.get
do encryption and
decryption using an executor. It will use the default
executor for your event loop if executor is None
.
PrivateBin API is offered under the MIT license.