Python Documentation
The sapling-py package provides a Python wrapper around the Sapling HTTP API.
Install or upgrade to the latest release:
python -m pip install --upgrade sapling-py
The methods below require sapling-py 4.1.0 or newer.
Language API methods
from sapling import SaplingClient
client = SaplingClient(api_key="<api-key>")
rephrases = client.rephrase(
"This is an example sentence.",
mapping="paraphrase",
num_results=3,
)
summary = client.summarize("A longer document to summarize...")
tones = client.tone("Thank you for resolving this so quickly!")
sentiment = client.sentiment("The support experience was excellent.")
quality = client.quality("Text to score for writing quality.")
language = client.langdetect("Bonjour tout le monde.")
profanity = client.profanity("Text to check.")
The client methods correspond to these API endpoints:
| Client method | API documentation |
|---|---|
rephrase() | Rephrase |
summarize() | Summarize |
tone() | Tone |
sentiment() | Sentiment |
quality() | Quality Score |
langdetect() | Language Detection |
profanity() | Profanity Detection |
See each endpoint page for input limits, optional parameters, and response formats.
Error handling
sapling-py raises SaplingError when the API returns a non-successful HTTP
status. The exception exposes both the status code and raw response body:
from sapling import SaplingClient, SaplingError
client = SaplingClient(api_key="<api-key>")
try:
result = client.summarize("Text to summarize.")
except SaplingError as error:
print(error.status_code)
print(error.body)
Network and timeout failures continue to use the exceptions raised by the
underlying requests library.
Complete SaplingClient reference documentation is available on
Read the Docs.