Python SDK
Install and use the RankVectors Python SDK
Installation
pip install rankvectors
Quick Start
from rankvectors import RankVectors
client = RankVectors(api_key="YOUR_API_KEY")
# Create a project
project = client.projects.create(
name="My Website",
domain="https://example.com",
preferred_sdk="python"
)
print(f"Project created: {project.id}")
Authentication
Include your API key when creating the client:
import os
from rankvectors import RankVectors
client = RankVectors(api_key=os.getenv("RANKVECTORS_API_KEY"))
Projects
Create Project
project = client.projects.create(
name="My Website",
domain="https://example.com",
preferred_sdk="python"
)
List Projects
projects = client.projects.list()
Get Project
project = client.projects.get(project_id)
Update Project
updated = client.projects.update(project_id, {
"name": "Updated Name",
"include_paths": ["/blog", "/docs"]
})
Delete Project
client.projects.delete(project_id)
Pages
Sync Page
client.pages.sync(project_id, {
"url": "https://example.com/page",
"content": "Page content...",
"title": "Page Title",
"status_code": 200
})
Batch Sync Pages
client.pages.batch_sync(project_id, [
{
"url": "https://example.com/page1",
"content": "Content 1...",
"title": "Page 1"
},
{
"url": "https://example.com/page2",
"content": "Content 2...",
"title": "Page 2"
}
])
List Pages
pages = client.pages.list(project_id, limit=50, offset=0)
Suggestions
Generate Suggestions
suggestions = client.suggestions.generate(project_id, {
"source_page_url": "https://example.com/page",
"limit": 10
})
List Suggestions
suggestions = client.suggestions.list(
project_id,
status="pending",
limit=50
)
Get Suggestion
suggestion = client.suggestions.get(project_id, suggestion_id)
Update Suggestion
client.suggestions.update(project_id, suggestion_id, {
"status": "approved"
})
Error Handling
from rankvectors.exceptions import APIError
try:
project = client.projects.create(
name="My Website",
domain="https://example.com"
)
except APIError as e:
if e.status_code == 401:
print("Authentication failed")
elif e.status_code == 429:
print("Rate limit exceeded")
else:
print(f"Error: {e.message}")
Async Support
The SDK supports async/await:
import asyncio
from rankvectors import RankVectors
async def main():
client = RankVectors(api_key="YOUR_API_KEY")
project = await client.projects.create_async(
name="My Website",
domain="https://example.com"
)
print(f"Project created: {project.id}")
asyncio.run(main())
More Examples
See the API Reference for complete API documentation.