Module pastebin :: Class PastebinAPI
[hide private]
[frames] | no frames]

Class PastebinAPI

source code

object --+
         |
        PastebinAPI

Pastebin API interaction object.

Public functions:

paste -- Pastes a user-specified file or string using the new API-key POST method.

legacy_paste -- Pastes a user-specified file or string using the old anonymous POST method.

generate_user_key -- Generates a session-key that is required for other functions.

pastes_by_user -- Returns all public pastes submitted by the specified login credentials.

trending -- Returns the top trending paste.

user_details -- Returns details about the user for the specified API user key.

delete_paste -- Adds two numbers together and returns the result.

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
String
delete_paste(self, api_dev_key, api_user_key, api_paste_key)
Delete the paste specified by the api_paste_key.
source code
string
user_details(self, api_dev_key, api_user_key)
Return user details of the user specified by the api_user_key.
source code
string
trending(self, api_dev_key)
Returns the top trending paste details.
source code
string
pastes_by_user(self, api_dev_key, api_user_key, results_limit=None)
Returns all pastes for the provided api_user_key.
source code
string
generate_user_key(self, api_dev_key, username, password)
Generate a user session key - needed for other functions.
source code
string
paste(self, api_dev_key, api_paste_code, api_user_key=None, paste_name=None, paste_format=None, paste_private=None, paste_expire_date=None)
Submit a code snippet to Pastebin using the new API.
source code
string
legacy_paste(self, paste_code, paste_name=None, paste_private=None, paste_expire_date=None, paste_format=None)
Unofficial python interface to the Pastebin legacy API.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  _bad_request = 'Bad API request'
  _base_domain = 'pastebin.com'
  _prefix_url = 'http://pastebin.com/'
  _subdomain_url = 'http://%s.pastebin.com/'
  _legacy_api_url = 'http://pastebin.com/api_public.php'
  _api_url = 'http://pastebin.com/api/api_post.php'
  _api_login_url = 'http://pastebin.com/api/api_login.php'
  paste_expire_date = ('N', '10M', '1H', '1D', '1M')
  paste_private = ('public', 'unlisted', 'private')
  paste_format = ('4cs', '6502acme', '6502kickass', '6502tasm', ...
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

delete_paste(self, api_dev_key, api_user_key, api_paste_key)

source code 

Delete the paste specified by the api_paste_key.

Usage Example:

   >>> from pastebin import PastebinAPI
   >>> x = PastebinAPI()
   >>> paste_to_delete = x.delete_paste('453a994e0e2f1efae07f8759e59e075b',
   ...                                 'c57a18e6c0ae228cd4bd16fe36da381a',
   ...                                 'WkgcTFtv')
   >>> print paste_to_delete
   Paste Removed     
Parameters:
  • api_dev_key (string) - The API Developer Key of a registered http://pastebin.com account.
  • api_user_key (string) - The API User Key of a http://pastebin.com registered user.
  • api_paste_key (string) - The Paste Key of the paste to be deleted (string after final / in http://pastebin.com URL).
Returns: String
A successful deletion returns 'Paste Removed'.

user_details(self, api_dev_key, api_user_key)

source code 

Return user details of the user specified by the api_user_key.

Usage Example:

   >>> from pastebin import PastebinAPI
   >>> x = PastebinAPI()
   >>> details = x.user_details('453a994e0e2f1efae07f8759e59e075b',
   ...                         'c57a18e6c0ae228cd4bd16fe36da381a')
   >>> print details
   <user>
   <user_name>MonkeyPuzzle</user_name>
   <user_format_short>python</user_format_short>
   <user_expiration>N</user_expiration>
   <user_avatar_url>http://pastebin.com/i/guest.gif</user_avatar_url>
   <user_private>0</user_private>
   <user_website></user_website>
   <user_email>user@email.com</user_email>
   <user_location></user_location>
   <user_account_type>0</user_account_type>
   </user>
Parameters:
Returns: string
Returns an XML string containing user information.

trending(self, api_dev_key)

source code 

Returns the top trending paste details.

Usage Example:

   >>> from pastebin import PastebinAPI
   >>> x = PastebinAPI()
   >>> details = x.trending('453a994e0e2f1efae07f8759e59e075b')
   >>> print details
   <paste>
   <paste_key>jjMRFDH6</paste_key>
   <paste_date>1333230838</paste_date>
   <paste_title></paste_title>
   <paste_size>6416</paste_size>
   <paste_expire_date>0</paste_expire_date>
   <paste_private>0</paste_private>
   <paste_format_long>None</paste_format_long>
   <paste_format_short>text</paste_format_short>
   <paste_url>http://pastebin.com/jjMRFDH6</paste_url>
   <paste_hits>6384</paste_hits>
   </paste>

Note: Returns multiple trending pastes, not just 1.

Parameters:
Returns: string
Returns the string (XML formatted) containing the top trending pastes.

pastes_by_user(self, api_dev_key, api_user_key, results_limit=None)

source code 

Returns all pastes for the provided api_user_key.

Usage Example:

   >>> from pastebin import PastebinAPI
   >>> x = PastebinAPI()
   >>> details = x.user_details('453a994e0e2f1efae07f8759e59e075b',
   ...                         'c57a18e6c0ae228cd4bd16fe36da381a',
   ...                         100)
   >>> print details
   <paste>
   <paste_key>DLiSspYT</paste_key>
   <paste_date>1332714730</paste_date>
   <paste_title>Pastebin.py - Python 3.2 Pastebin.com API</paste_title>
   <paste_size>25300</paste_size>
   <paste_expire_date>0</paste_expire_date>
   <paste_private>0</paste_private>
   <paste_format_long>Python</paste_format_long>
   <paste_format_short>python</paste_format_short>
   <paste_url>http://pastebin.com/DLiSspYT</paste_url>
   <paste_hits>70</paste_hits>
   </paste>

Note: Returns multiple pastes, not just 1.

Parameters:
  • api_dev_key (string) - The API Developer Key of a registered http://pastebin.com account.
  • api_user_key (string) - The API User Key of a http://pastebin.com registered user.
  • results_limit (number) - The number of pastes to return between 1 - 1000.
Returns: string
Returns an XML string containing number of specified pastes by user.

generate_user_key(self, api_dev_key, username, password)

source code 

Generate a user session key - needed for other functions.

Usage Example:

   >>> from pastebin import PastebinAPI
   >>> x = PastebinAPI()
   >>> my_key = x.generate_user_key('453a994e0e2f1efae07f8759e59e075b',
   ...                             'MonkeyPuzzle',
   ...                             '12345678')
   >>> print my_key
   c57a18e6c0ae228cd4bd16fe36da381a
Parameters:
Returns: string
Session key (api_user_key) to allow authenticated interaction to the API.

paste(self, api_dev_key, api_paste_code, api_user_key=None, paste_name=None, paste_format=None, paste_private=None, paste_expire_date=None)

source code 

Submit a code snippet to Pastebin using the new API.

Usage Example:

   >>> from pastebin import PastebinAPI
   >>> x = PastebinAPI()
   >>> url = x.paste('453a994e0e2f1efae07f8759e59e075b' ,
   ...               'Snippet of code to paste goes here',
   ...               paste_name = 'title of paste',
   ...               api_user_key = 'c57a18e6c0ae228cd4bd16fe36da381a', 
   ...               paste_format = 'python',
   ...               paste_private = 'unlisted',
   ...               paste_expire_date = '10M')
   >>> print url
   http://pastebin.com/tawPUgqY
Parameters:
  • api_dev_key (string) - The API Developer Key of a registered http://pastebin.com account.
  • api_paste_code (string) - The file or string to paste to body of the http://pastebin.com paste.
  • api_user_key (string) - The API User Key of a http://pastebin.com registered user. If none specified, paste is made as a guest.
  • paste_name (string) - (Optional) Title of the paste. Default is to paste anonymously.
  • paste_format (string) - (Optional) Programming language of the code being pasted. This enables syntax highlighting when reading the code in http://pastebin.com. Default is no syntax highlighting (text is just text and not source code).
  • paste_private (string) - (Optional) 'public' if the paste is public (visible by everyone), 'unlisted' if it's public but not searchable. 'private' if the paste is private and not searchable or indexed. The Pastebin FAQ (http://pastebin.com/faq) claims private pastes are not indexed by search engines (aka Google).
  • paste_expire_date (str) - (Optional) Expiration date for the paste. Once past this date the paste is deleted automatically. Valid values are found in the PastebinAPI.paste_expire_date class member. If not provided, the paste never expires.
Returns: string
Returns the URL to the newly created paste.

legacy_paste(self, paste_code, paste_name=None, paste_private=None, paste_expire_date=None, paste_format=None)

source code 

Unofficial python interface to the Pastebin legacy API.

Unlike the official API, this one doesn't require an API key, so it's virtually anonymous.

Usage Example:

   >>> from pastebin import PastebinAPI
   >>> x = PastebinAPI()
   >>> url = x.legacy_paste('Snippet of code to paste goes here',
   ...                     paste_name = 'title of paste',
   ...                     paste_private = 'unlisted',
   ...                     paste_expire_date = '10M',
   ...                     paste_format = 'python')
   >>> print url
   http://pastebin.com/tawPUgqY
Parameters:
  • paste_code (string) - The file or string to paste to body of the http://pastebin.com paste.
  • paste_name (string) - (Optional) Title of the paste. Default is to paste with no title.
  • paste_private (string) - (Optional) 'public' if the paste is public (visible by everyone), 'unlisted' if it's public but not searchable. 'private' if the paste is private and not searchable or indexed. The Pastebin FAQ (http://pastebin.com/faq) claims private pastes are not indexed by search engines (aka Google).
  • paste_expire_date (string) - (Optional) Expiration date for the paste. Once past this date the paste is deleted automatically. Valid values are found in the PastebinAPI.paste_expire_date class member. If not provided, the paste never expires.
  • paste_format (string) - (Optional) Programming language of the code being pasted. This enables syntax highlighting when reading the code in http://pastebin.com. Default is no syntax highlighting (text is just text and not source code).
Returns: string
Returns the URL to the newly created paste.

Class Variable Details [hide private]

paste_format

Value:
('4cs',
 '6502acme',
 '6502kickass',
 '6502tasm',
 'abap',
 'actionscript',
 'actionscript3',
 'ada',
...