API

SpinRewriter

class spinrewriter.SpinRewriter(email_address, api_key)[source]

A facade for easier usage of the raw Spin Rewriter API.

text_with_spintax(text, confidence_level='medium')[source]

Return text with spintax elements inserted.

Parameters:
  • text (string) – text to process
  • confidence_level (Api.CONFIDENCE_LVL) – how ‘confident’ the spinner API is when transforming the text
Returns:

original text with spintax elements

Return type:

string

unique_variation(text, confidence_level='medium')[source]

Return unique variation of the given text.

Parameters:
  • text (string) – text to process
  • confidence_level (Api.CONFIDENCE_LVL) – how ‘confident’ the spinner API is when transforming the text
Returns:

spinned version of the original text

Return type:

string

Raw API access

class spinrewriter.Api(email_address, api_key)[source]

A class representing the Spin Rewriter API (http://www.spinrewriter.com/).

ACTION = ACTION(api_quota='api_quota', text_with_spintax='text_with_spintax', unique_variation='unique_variation', unique_variation_from_spintax='unique_variation_from_spintax')

collection of possible values for the action parameter

CONFIDENCE_LVL = CONFIDENCE_LVL(low='low', medium='medium', high='high')

collection of possible values for the confidence_level parameter

REQ_P_NAMES = REQ_P_NAMES(email_address='email_address', api_key='api_key', action='action', text='text', protected_terms='protected_terms', confidence_level='confidence_level', nested_spintax='nested_spintax', spintax_format='spintax_format')

collection of all request parameters’ names

RESP_P_NAMES = RESP_P_NAMES(status='status', response='response', api_requests_made='api_requests_made', api_requests_available='api_requests_available', protected_terms='protected_terms', confidence_level='confidence_level')

collection of all response fields’ names

SPINTAX_FORMAT = SPINTAX_FORMAT(pipe_curly='{|}', tilde_curly='{~}', pipe_square='[|]', spin_tag='[spin]')

collection of possible values for the spintax_format parameter

STATUS = STATUS(ok='OK', error='ERROR')

possible response status strings returned by API

URL = 'http://www.spinrewriter.com/action/api'

URL for invoking the API

_raise_error(api_response)[source]

Examine the API response and raise exception of the appropriate type.

NOTE: usage of this method only makes sense when API response’s status indicates an error

Parameters:api_response (dictionary) – API’s response fileds
_send_request(params)[source]

Invoke Spin Rewriter API with given parameters and return its response.

Parameters:params (tuple of 2-tuples) – parameters to pass along with the request
Returns:API’s response (already JSON-decoded)
Return type:dictionary
_transform_plain_text(action, text, protected_terms, confidence_level, nested_spintax, spintax_format)[source]

Transform plain text using SpinRewriter API.

Pack parameters into format as expected by the _send_request method and invoke the action method to get transformed text from the API.

Parameters:
  • action (string) – name of the action that will be requested from API
  • text (string) – text to process
  • protected_terms (list of strings) – keywords and key phrases that should be left intact
  • confidence_level (string) – the confidence level of the One-Click Rewrite process
  • nested_spintax (boolean) – whether or not to also spin single words inside already spun phrases
  • spintax_format (string) – spintax format to use in returned text
Returns:

processed text and some other meta info

Return type:

dictionary

api_quota()[source]

Return the number of made and remaining API calls for the 24-hour period.

Returns:remaining API quota
Return type:dictionary
text_with_spintax(text, protected_terms=None, confidence_level='medium', nested_spintax=False, spintax_format='{|}')[source]

Return processed spun text with spintax.

Parameters:
  • text (string) – original text that needs to be changed
  • protected_terms (list of strings) – (optional) keywords and key phrases that should be left intact
  • confidence_level (string) – (optional) the confidence level of the One-Click Rewrite process
  • nested_spintax (boolean) – (optional) whether or not to also spin single words inside already spun phrases
  • spintax_format (string) – (optional) spintax format to use in returned text
Returns:

processed text and some other meta info

Return type:

dictionary

unique_variation(text, protected_terms=None, confidence_level='medium', nested_spintax=False, spintax_format='{|}')[source]

Return a unique variation of the given text.

Parameters:
  • text (string) – original text that needs to be changed
  • protected_terms (list of strings) – (optional) keywords and key phrases that should be left intact
  • confidence_level (string) – (optional) the confidence level of the One-Click Rewrite process
  • nested_spintax (boolean) – (optional) whether or not to also spin single words inside already spun phrases
  • spintax_format (string) – (optional) (probably not relevant here? But API documentation not clear here ...)
Returns:

processed text and some other meta info

Return type:

dictionary

unique_variation_from_spintax(text, nested_spintax=False, spintax_format='{|}')[source]

Return a unique variation of an already spun text.

Parameters:
  • text (string) – text to process
  • nested_spintax (boolean) – whether or not to also spin single words inside already spun phrases
  • spintax_format (string) – (probably not relevant here? But API documentation not clear here ...)
Returns:

processed text and some other meta info

Return type:

dictionary

Exceptions

exception spinrewriter.exceptions.AuthenticationError(api_error_msg)[source]

Raised when authentication error occurs.

exception spinrewriter.exceptions.InternalApiError(api_error_msg)[source]

Raised when unexpected error occurs on the API server when processing a request.

exception spinrewriter.exceptions.MissingParameterError(api_error_msg)[source]

Raised when required parameter is not provided.

exception spinrewriter.exceptions.ParamValueError(api_error_msg)[source]

Raised when parameter passed to API call has an invalid value.

exception spinrewriter.exceptions.QuotaLimitError(api_error_msg)[source]

Raised when API quota limit is reached.

exception spinrewriter.exceptions.SpinRewriterApiError(api_error_msg)[source]

Base class for exceptions in Spin Rewriter module.

exception spinrewriter.exceptions.UnknownActionError(api_error_msg)[source]

Raised when unknown API action is requested.

exception spinrewriter.exceptions.UnknownApiError(api_error_msg)[source]

Raised when API call results in an unrecognized error.

exception spinrewriter.exceptions.UsageFrequencyError(api_error_msg)[source]

Raised when subsequent API requests are made in a too short time interval.