Python tone checker quickstart
Send text to the tone endpoint. The response ranks overall tones and returns a separate probability breakdown for every sentence.
import os
from pprint import pprint
import requests
api_key = os.environ.get("SAPLING_API_KEY")
if not api_key:
raise RuntimeError("Set SAPLING_API_KEY first.")
response = requests.post(
"https://api.sapling.ai/api/v1/tone",
headers={"Authorization": f"Bearer {api_key}"},
json={
"text": "Really stoked about this! Will it be ready by next week?",
},
timeout=30,
)
response.raise_for_status()
pprint(response.json())
{
"overall": [
[0.9247, "curious", "🤓"],
[0.0455, "excited", "😀"],
[0.0057, "confused", "😕"]
],
"results": [
[[0.9937, "excited", "😀"]],
[[0.5469, "confused", "😕"], [0.3993, "curious", "🤓"]]
],
"sents": [
"Really stoked about this!",
"Will it be ready by next week?"
]
}
Probabilities are returned in descending order as probability, tone, and emoji tuples. Use sentence results when a message contains mixed tones.
About Python
Python is a high-level interpreted general-purpose scripting language that ranks as one of the most popular programming languages. It is designed to be readable and uses indentation as part of its syntax. The reference implementation, CPython is written in both C and Python, which provides the performance characteristics of C for computationally expensive number-crunching tasks.