Pastebin Class

class pbwrap.Pastebin(api_dev_key=None, verify_ssl=True)[source]

Pastebin class represents your communication with the Pastebin API through its functions you can use every API endpoint avalaible.

Most functions require at least an api_dev_key parameter. Functions for manipulating your pastes through the API require an api_user_key.

Instantiate a Pastebin Object

Parameters:
  • api_dev_key (string) – Your API Pastebin key
  • verify_ssl (bool) – If False, does not verify ssl certificate. Default: True
authenticate(username, password)[source]

Authenticate through the API login endpoint Your api_user_key attribute is set automatically

Parameters:
  • username (string) – Your username
  • password (string) – Your password
Returns:

your user_id key

Return type:

string

create_paste(api_paste_code, api_paste_private=0, api_paste_name=None, api_paste_expire_date=None, api_paste_format=None)[source]

Create a new paste if succesfull return it’s url.

Parameters:
  • api_paste_code (string) – your paste text
  • api_paste_private (int) – valid values=0(public),1(unlisted),2(private)
  • api_user_name – your paste name
  • api_paste_expire_date (string) – check documentation for valid values
  • api_paste_format (string) – check documentation for valid values
Returns:

new paste url

Return type:

string

create_paste_from_file(filepath, api_paste_private=0, api_paste_name=None, api_paste_expire_date=None, api_paste_format=None)[source]

Create a new paste from file if succesfull return it’s url.

Parameters:
  • filepath (string) – the path of the file
  • api_paste_private (int) – valid values=0(public),1(unlisted),2(private)
  • api_user_name – your paste name
  • api_paste_expire_date (string) – check documentation for valid values
  • api_paste_format (string) – check documentation for valid values
Returns:

new paste url

Return type:

string

delete_user_paste(api_paste_key)[source]

Deletes a paste created by the user.

Parameters:api_paste_key (string) – the id key of the paste you want to delete
Returns:api response
Return type:string
general_params()[source]

Returns parameters that should be included in every request

Returns:The options to be passed to requests.*
Return type:dictionary
get_archive()[source]

Return archive paste link list.Archive contains 25 most recent pastes.

Returns:a list of url strings
Return type:list
get_raw_paste(paste_id)[source]

Return raw string of given paste_id.

get_raw_paste(pasted_id)

Parameters:paste_id (string) – The ID key of the paste
Returns:the text of the paste
Return type:string
static get_recent_pastes(limit=50, lang=None)[source]

Return a list containing dictionaries of paste.

Parameters:
  • limit (int) – the limit of the items returned defaults to 50
  • lang (string) – return only pastes from certain language defaults to None
Returns:

list of Paste objects.

Return type:

list(Paste)

Return a list of paste objects created from the most trending pastes

Returns:a list of Paste objects
Return type:list
get_user_details()[source]

Return user details in a dictionary. Can only be user after authenticating with get_user_id(username, password).

Returns:dictionary containing user details
Return type:dictionary
get_user_pastes(api_results_limit=None)[source]

Return a list of Pastes created from the user

Parameters:api_results_limit (int) – min=1, max=1000
Returns:a list of Pastes created from the user
Return type:list
get_user_raw_paste(api_paste_key)[source]

Return the raw data of a user paste(even private pastes!) as string.

Parameters:api_paste_key (string) – the id key of the paste you want to fetch
Returns:the text of the paste
Return type:string
static scrape_paste_metadata(paste_key)[source]

Return a dictionary containing the metadata of the paste.

Parameters:paste_key (string) – the unique key of the paste you want to scrape
Returns:dictionary containing the metadata of the paste
Return type:dictionary
static scrape_raw_paste(paste_key)[source]

Return a string containing the text of the paste.

Parameters:paste_key (string) – the unique key of the paste you want to scrape
Returns:raw string containing the text of the paste
Return type:string