Access the Mermru Linguistic Engine via our API.
Explore and test all API endpoints directly in your browser. Ideal for quick testing and debugging.
Go to Swagger UIRead the comprehensive, clean, single-page reference documentation. Ideal for understanding structure and architecture.
Go to ReDocYou can access the API from any script or application. Access requires a three-step process:
/api/token/ endpoint. You will receive an access token (which expires in 1 year) and a refresh token.Authorization header of your API requests, using the Bearer keyword.You can use the following script to get started. Make sure you have the `requests` library installed (`pip install requests`).
import requests
import json
import getpass
# --- Configuration ---
BASE_URL = "https://mermru.com" # The production API domain
# 1. Get credentials securely
USERNAME = input("Enter your username: ")
PASSWORD = getpass.getpass("Enter your password: ")
ACCESS_TOKEN = None
# --- Step 1: Get Authentication Token (JWT) ---
print("Attempting to get auth token...")
try:
auth_response = requests.post(
f"{BASE_URL}/api/token/", # Use the new JWT endpoint
json={"username": USERNAME, "password": PASSWORD}
)
auth_response.raise_for_status() # Raise an exception for bad status codes
# Get the ACCESS token from the response
ACCESS_TOKEN = auth_response.json().get("access")
# You can also get the refresh token if you need to:
# REFRESH_TOKEN = auth_response.json().get("refresh")
print(f"Successfully obtained access token: {ACCESS_TOKEN[:10]}...")
except requests.exceptions.RequestException as e:
print(f"Error getting auth token: {e}")
if auth_response.status_code == 400:
print("Error: Bad request. Please check your username and password.")
else:
print(f"Response: {auth_response.text}")
exit()
if not ACCESS_TOKEN:
print("Could not retrieve API token. Check credentials.")
exit()
# --- Step 2: Make an Authenticated API Request ---
try:
search_word = "love"
# Use the JWT 'Bearer' token scheme
headers = {"Authorization": f"Bearer {ACCESS_TOKEN}"}
# Use the filter field 'word' for an exact match
params = {"word": search_word}
print(f"Searching for exact word: '{search_word}'")
api_response = requests.get(
f"{BASE_URL}/api/pronunciations/",
headers=headers,
params=params
)
api_response.raise_for_status()
data = api_response.json()
print("\n--- API Response (Exact Match) ---")
print(json.dumps(data, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error making API request: {e}")
if api_response:
print(f"Response: {api_response.json()}")