Skip to content

API

paspybin.api

Paspybin

Bases: API

Main Pastebin API class.

login(username, password) async

Authenticating to Pastebin API based on credential auth given.

Parameters:

Name Type Description Default
username str

username of user.

required
password str

password of user.

required

Raises:

Type Description
PaspybinBadAPIRequestError

if a bad request is sent to the API.

ValueError

if dev_key not supplied.

Examples:

>>> import asyncio
>>> import os
>>> PASTEBIN_API_DEV_KEY = os.environ["PASTEBIN_API_DEV_KEY"]
>>> PASTEBIN_USERNAME = os.environ["PASTEBIN_USERNAME"]
>>> PASTEBIN_PASSWORD = os.environ["PASTEBIN_PASSWORD"]
>>> async def main():
...     async with Paspybin(PASTEBIN_API_DEV_KEY) as paspybin:
...         await paspybin.login(PASTEBIN_USERNAME, PASTEBIN_PASSWORD)
>>> asyncio.run(main())

logout()

Logging out the currently logged in user.

Examples:

>>> import asyncio
>>> import os
>>> PASTEBIN_API_DEV_KEY = os.environ["PASTEBIN_API_DEV_KEY"]
>>> PASTEBIN_USERNAME = os.environ["PASTEBIN_USERNAME"]
>>> PASTEBIN_PASSWORD = os.environ["PASTEBIN_PASSWORD"]
>>> async def main():
...     async with Paspybin(PASTEBIN_API_DEV_KEY) as paspybin:
...         await paspybin.login(PASTEBIN_USERNAME, PASTEBIN_PASSWORD)
...         paspybin.logout()
>>> asyncio.run(main())

Paste

Bases: API, Paste

Paste API wrapper.

delete() async

Delete a paste owned by user.

Raises:

Type Description
PaspybinBadAPIRequestError

if a bad request is sent to the API.

ValueError

if dev_key not supplied.

ValueError

if guest use this method.

Examples:

>>> import asyncio
>>> import os
>>> from paspybin import Paspybin
>>> PASTEBIN_API_DEV_KEY = os.environ["PASTEBIN_API_DEV_KEY"]
>>> PASTEBIN_API_USER_KEY = os.environ["PASTEBIN_API_USER_KEY"]
>>> async def main():
...     async with Paspybin(
...         PASTEBIN_API_DEV_KEY, PASTEBIN_API_USER_KEY
...     ) as paspybin:
...         async for paste in paspybin.pastes.get_all():
...             # paste.delete()
...             pass
>>> asyncio.run(main())

get_content() async

Get the pasted content.

Returns:

Type Description
str

A string of paste content.

Raises:

Type Description
PaspybinBadAPIRequestError

if a bad request is sent to the API.

ValueError

if dev_key not supplied.

ValueError

if guest use this method.

Examples:

>>> import asyncio
>>> import os
>>> from paspybin import Paspybin
>>> PASTEBIN_API_DEV_KEY = os.environ["PASTEBIN_API_DEV_KEY"]
>>> PASTEBIN_API_USER_KEY = os.environ["PASTEBIN_API_USER_KEY"]
>>> async def main():
...     async with Paspybin(
...         PASTEBIN_API_DEV_KEY, PASTEBIN_API_USER_KEY
...     ) as paspybin:
...         async for paste in paspybin.pastes.get_all():
...             paste_content = await paste.get_content()
...             # do what you want to do with paste content here
>>> asyncio.run(main())

Pastes

Bases: API

create_paste(content, title=None, format=None, visibility=None, expire=None, folder_key=None) async

Create a new paste.

Parameters:

Name Type Description Default
content str

The paste content that you want to create.

required
title str | None

title of the paste.

None
format Format | None

syntax highlighting format of the paste.

None
visibility Visibility | None

visibility of the paste.

None
expire Expire | None

expire of the paste.

None
folder_key FolderKey | None

a folder that you want to store the paste.

None

Returns:

Type Description
PasteKey

A paste key.

Raises:

Type Description
PaspybinBadAPIRequestError

if a bad request is sent to the API.

ValueError

if dev_key not supplied.

ValueError

if the paste content is empty.

ValueError

if the paste visibility is private for guest.

Examples:

>>> import asyncio
>>> import os
>>> from paspybin import Paspybin
>>> PASTEBIN_API_DEV_KEY = os.environ["PASTEBIN_API_DEV_KEY"]
>>> async def main():
...     async with Paspybin(PASTEBIN_API_DEV_KEY) as paspybin:
...         paste_content = "some paste content"
...         paste_key = await paspybin.pastes.create_paste(paste_content)
...         # do what you want to do with paste key here
>>> asyncio.run(main())

get_all(limit=None) async

Get list of pastes owned by user.

Parameters:

Name Type Description Default
limit int | None

Length limit of the paste list. By default the limit is 50, the minimum limit is 1 and the maximum limit is 1000.

None

Yields:

Type Description
AsyncIterator[Paste]

Some pastes.

Raises:

Type Description
PaspybinBadAPIRequestError

if a bad request is sent to the API.

ValueError

if dev_key not supplied.

ValueError

if guest use this method.

ValueError

if the limit value is less than 1 or more than 1000.

Examples:

>>> import asyncio
>>> import os
>>> from paspybin import Paspybin
>>> PASTEBIN_API_DEV_KEY = os.environ["PASTEBIN_API_DEV_KEY"]
>>> PASTEBIN_API_USER_KEY = os.environ["PASTEBIN_API_USER_KEY"]
>>> async def main():
...     async with Paspybin(
...         PASTEBIN_API_DEV_KEY, PASTEBIN_API_USER_KEY
...     ) as paspybin:
...         async for paste in paspybin.pastes.get_all():
...             # do what you want to do with paste here
...             pass
>>> asyncio.run(main())

get_content(paste_key) async

Get the public or unlisted pasted content.

Parameters:

Name Type Description Default
paste_key PasteKey

A paste key of the paste content that you want to get.

required

Returns:

Type Description
str

A string of paste content.

Raises:

Type Description
PaspybinNotFoundError

if paste content not found.

Examples:

>>> import asyncio
>>> from paspybin import Paspybin
>>> async def main():
...     async with Paspybin() as paspybin:
...         paste_key = "0C343n0d"
...         paste_content = await paspybin.pastes.get_content(paste_key)
...         # do what you want to do with paste content here
>>> asyncio.run(main())

User

Bases: API

get_detail() async

Get a user detail.

Returns:

Type Description
User

A User schema.

Raises:

Type Description
PaspybinBadAPIRequestError

if a bad request is sent to the API.

ValueError

if dev_key not supplied.

ValueError

if guest use this method.

Examples:

>>> import asyncio
>>> import os
>>> from paspybin import Paspybin
>>> PASTEBIN_API_DEV_KEY = os.environ["PASTEBIN_API_DEV_KEY"]
>>> PASTEBIN_API_USER_KEY = os.environ["PASTEBIN_API_USER_KEY"]
>>> async def main():
...     async with Paspybin(
...         PASTEBIN_API_DEV_KEY, PASTEBIN_API_USER_KEY
...     ) as paspybin:
...         print(await paspybin.user.get_detail())
>>> asyncio.run(main())
User(...)