Quickstart: Python
Integrate ReachScore into your Python application.
1
Install the SDK
Install the official ReachScore Python SDK using pip:
pip install reachscore
2
Initialize the client
Create a new client instance with your API key:
import os from reachscore import ReachScore client = ReachScore(api_key=os.environ["REACHSCORE_API_KEY"])
3
Create a test
Create a new deliverability test:
test = client.tests.create(
from_address="notifications@yourcompany.com",
subject="Test email deliverability"
)
print(f"Send your email to: {test.test_address}")
# test.test_address = "test_7xK2mN9p@inbound.reachscore.co"4
Get the results
After sending your email, retrieve the test results:
# Poll for results (or use webhooks)
result = client.tests.get(test.id)
if result.status == "completed":
print(f"Deliverability Score: {result.score}")
print(f"Grade: {result.grade}")
print(f"SPF: {result.auth_results.spf}")
print(f"DKIM: {result.auth_results.dkim}")
print(f"DMARC: {result.auth_results.dmarc}")Complete Example
Here is a full working example that creates a test and waits for results:
import os
import time
from reachscore import ReachScore
def run_deliverability_test():
client = ReachScore(api_key=os.environ["REACHSCORE_API_KEY"])
# Create the test
test = client.tests.create(
from_address="notifications@yourcompany.com",
subject="Weekly newsletter"
)
print(f"Test created: {test.id}")
print(f"Send email to: {test.test_address}")
# Wait for results (in production, use webhooks instead)
result = test
while result.status not in ["completed", "failed"]:
time.sleep(5)
result = client.tests.get(test.id)
print(f"Status: {result.status}")
if result.status == "completed":
print(f"Score: {result.score}/100 (Grade: {result.grade})")
print(f"Auth: SPF={result.auth_results.spf}, DKIM={result.auth_results.dkim}, DMARC={result.auth_results.dmarc}")
if __name__ == "__main__":
run_deliverability_test()Async Support
The SDK also supports async/await for use with asyncio:
import asyncio
from reachscore import AsyncReachScore
async def main():
client = AsyncReachScore(api_key=os.environ["REACHSCORE_API_KEY"])
test = await client.tests.create(
from_address="notifications@yourcompany.com",
subject="Test email"
)
# Later...
result = await client.tests.get(test.id)
print(f"Score: {result.score}")
asyncio.run(main())Error Handling
The SDK raises specific exceptions for different error types:
from reachscore import ReachScore
from reachscore.errors import (
AuthenticationError,
RateLimitError,
InvalidRequestError,
NotFoundError,
)
client = ReachScore(api_key=os.environ["REACHSCORE_API_KEY"])
try:
test = client.tests.get("test_invalid_id")
except NotFoundError as e:
print(f"Test not found: {e.message}")
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after} seconds")
except AuthenticationError as e:
print(f"Auth error: {e.message}")