Python grammar checker quickstart
Send text to the edits endpoint. Sapling returns suggested replacements with character offsets so your application can review or apply each correction.
Sapling provides an SDK for this stack. The direct HTTP example below remains useful for server-side integrations; see the SDK overview for the higher-level client.
Python
/api/v1/edits
import requests
key = '<API_KEY>'
url = 'https://api.sapling.ai/api/v1/edits'
data = {
'key': key,
'text': 'Lets get started',
'session_id': 'Test Document UUID',
}
try:
resp = requests.post(url, json=data)
resp_json = resp.json()
if 200 <= resp.status_code < 300:
edits = resp_json['edits']
print('Edits: ', edits)
else:
print('Error: ', resp_json)
except Exception as e:
print('Error: ', e)
Example response
application/json
{
"edits": [
{
"start": 0,
"end": 4,
"replacement": "Let's",
"sentence": "Lets get started!",
"error_type": "R:OTHER"
}
]
}
Each edit identifies the source range and replacement text. Preserve the original offsets when applying more than one edit.
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.