API Reference¶
This section contains the full API reference for all public classes and functions.
Client¶
Vairified SDK Client
Async-first client for the Vairified Partner API.
- class vairified.client.Vairified[source]¶
Bases:
objectAsync client for the Vairified Partner API.
- Variables:
api_key – Your Partner API key
base_url – API base URL
env – Environment name (production, staging, local)
Example:
async with Vairified(api_key="vair_pk_xxx") as client: member = await client.get_member("user_123") print(member.name, member.rating)
Example with staging environment:
async with Vairified(api_key="vair_pk_xxx", env="staging") as client: member = await client.get_member("user_123")
Note
If your API key has the “dry-run” scope, match submissions will be validated but not persisted. This is useful for testing integrations.
- Parameters:
- __init__(api_key=None, *, env=None, base_url=None, timeout=30.0)[source]¶
Initialize the Vairified client.
- Parameters:
api_key (
Optional[str] (default:None)) – Partner API key. Falls back toVAIRIFIED_API_KEYenv var.env (
Optional[str] (default:None)) – Environment: “production” (default), “staging”, or “local”.base_url (
Optional[str] (default:None)) – Override API base URL. Takes precedence overenv.timeout (
float(default:30.0)) – Request timeout in seconds.
- Raises:
ValueError – If no API key is provided.
- async get_member(player_id)[source]¶
Get a connected member by their external ID.
Requires OAuth Connection: The player must have connected their account to your application via OAuth before you can access their data.
- Parameters:
player_id (
str) – External player ID (vair_mem_xxx format).- Return type:
- Returns:
Member object with profile and rating data.
- Raises:
NotFoundError – If member is not found or invalid ID format.
ForbiddenError – If player has not connected to your app.
Example:
member = await client.get_member("vair_mem_0ABC123def456GHI789jk") print(f"{member.name}: {member.rating}")
- async search(*, name=None, city=None, state=None, country=None, zip_code=None, rating_min=None, rating_max=None, gender=None, vairified_only=False, age=None, age_min=None, age_max=None, sort_by=None, sort_order='desc', page=1, limit=20)[source]¶
Search for players.
- Parameters:
name (
Optional[str] (default:None)) – Name to search for (partial match).state (
Optional[str] (default:None)) – State code (e.g., “TX”, “CA”).country (
Optional[str] (default:None)) – Country code (e.g., “US”).rating_min (
Optional[float] (default:None)) – Minimum rating (2.0-8.0).rating_max (
Optional[float] (default:None)) – Maximum rating (2.0-8.0).gender (
Optional[str] (default:None)) – “MALE” or “FEMALE”.vairified_only (
bool(default:False)) – Only return verified players.age_min (
Optional[int] (default:None)) – Minimum age (for range).age_max (
Optional[int] (default:None)) – Maximum age (for range).sort_order (
str(default:'desc')) – “asc” or “desc”.page (
int(default:1)) – Page number (1-indexed).limit (
int(default:20)) – Results per page (max 100).
- Return type:
- Returns:
SearchResults with players and pagination info.
Example:
results = await client.search(city="Austin", rating_min=4.0) for player in results: print(f"{player.name}: {player.rating}") # Pagination if results.has_more: next_results = await results.next_page()
- async find_player(name)[source]¶
Find a single player by name.
Convenience method that returns the first match.
- async submit_match(match)[source]¶
Submit a single match.
- Parameters:
match (
Match) – Match object with teams and scores.- Return type:
- Returns:
MatchResult with submission status.
- Raises:
VairifiedError – If submission fails.
Example:
match = Match( event="Weekly League", bracket="4.0 Doubles", date=datetime.now(), team1=("player1_id", "player2_id"), team2=("player3_id", "player4_id"), scores=[(11, 9), (11, 7)], ) result = await client.submit_match(match) if result: print(f"Submitted {result.num_games} games")
- async submit_matches(matches)[source]¶
Submit multiple matches in a batch.
- Parameters:
- Return type:
- Returns:
MatchResult with
success,num_matches,num_games, and optionallydry_run,message,errors.
Example:
matches = [match1, match2, match3] result = await client.submit_matches(matches) if result: print(f"Submitted {result.num_games} games") if result.dry_run: print("This was a dry run - no data persisted")
- async get_rating_updates()[source]¶
Get rating updates for subscribed members.
Members are subscribed when you call
get_member().- Return type:
- Returns:
List of RatingUpdate objects.
Example:
updates = await client.get_rating_updates() for update in updates: print(f"{update.member_id}: {update.previous_rating}")
- async start_oauth(redirect_uri, scopes=None, state=None)[source]¶
Start an OAuth authorization flow.
This creates a pending authorization and returns the URL where users should be redirected to approve access.
- Parameters:
- Return type:
- Returns:
AuthorizationResponse with the URL to redirect users to.
- Raises:
OAuthError – If the authorization fails to start.
Example:
auth = await client.start_oauth( redirect_uri="https://myapp.com/callback", scopes=["profile:read", "rating:read", "match:submit"], state="random_csrf_token", ) # Redirect user to auth.authorization_url
- async exchange_token(code, redirect_uri)[source]¶
Exchange an authorization code for access and refresh tokens.
Call this after the user approves access and is redirected back to your application with a code parameter.
- Parameters:
- Return type:
- Returns:
TokenResponse with access_token, refresh_token, and player_id.
- Raises:
OAuthError – If the code is invalid or expired.
Example:
# After user is redirected to: https://myapp.com/callback?code=xxx tokens = await client.exchange_token( code=request.query_params["code"], redirect_uri="https://myapp.com/callback", ) # Store tokens.access_token and tokens.refresh_token securely # Use tokens.player_id to identify the connected player
- async refresh_access_token(refresh_token)[source]¶
Refresh an expired access token.
Use this when an access token expires to obtain a new one without requiring the user to re-authorize.
- Parameters:
refresh_token (
str) – The refresh token from a previous token exchange.- Return type:
- Returns:
TokenResponse with new access_token and optionally a new refresh_token.
- Raises:
OAuthError – If the refresh token is invalid or revoked.
Example:
try: new_tokens = await client.refresh_access_token(stored_refresh_token) # Update stored tokens except OAuthError as e: if e.error_code == "invalid_grant": # Refresh token revoked, user needs to re-authorize pass
- async revoke_connection(player_id)[source]¶
Revoke a player’s OAuth connection.
This disconnects the player from your application. You will no longer be able to access their data or submit matches on their behalf.
- Parameters:
player_id (
str) – The player’s external ID (vair_mem_xxx format).- Return type:
- Returns:
Dict with success status.
- Raises:
OAuthError – If the revocation fails.
Example:
await client.revoke_connection("vair_mem_0ABC123def456GHI789jk") # Player is now disconnected
- async get_available_scopes()[source]¶
Get a list of available OAuth scopes.
Example:
scopes = await client.get_available_scopes() for scope in scopes: print(f"{scope['id']}: {scope['description']}")
- async get_usage()[source]¶
Get API usage statistics for your partner account.
- Return type:
- Returns:
Dict with usage statistics (requests, limits, etc.).
Example:
usage = await client.get_usage() print(f"Requests today: {usage['requestsToday']}") print(f"Rate limit: {usage['rateLimit']}/hour")
- async get_leaderboard(*, category=None, age_bracket=None, scope=None, state=None, city=None, club_id=None, gender=None, verified_only=False, min_games=None, limit=50, offset=0, search=None)[source]¶
Get leaderboard data with filtering options.
Requires API Key Scope:
leaderboard:readorread- Parameters:
category (
Optional[str] (default:None)) – Rating category: “doubles”, “singles”, “mixed” (default: doubles).age_bracket (
Optional[str] (default:None)) – Age bracket: “open”, “40+”, “50+”, “60+”, “70+” (default: open).scope (
Optional[str] (default:None)) – Geographic scope: “global”, “state”, “city”, “club” (default: global).state (
Optional[str] (default:None)) – State code (required if scope is “state”).city (
Optional[str] (default:None)) – City name (required if scope is “city”).club_id (
Optional[str] (default:None)) – Club ID (required if scope is “club”).gender (
Optional[str] (default:None)) – Filter by gender: “male”, “female”.verified_only (
bool(default:False)) – Only show VAIRified players.min_games (
Optional[int] (default:None)) – Minimum games to appear (default: 10).limit (
int(default:50)) – Results per page (default: 50, max: 100).offset (
int(default:0)) – Pagination offset.search (
Optional[str] (default:None)) – Search by player name.
- Return type:
- Returns:
Dict with players, stats, filters, and pagination.
Example:
# Get global doubles leaderboard leaderboard = await client.get_leaderboard() # Get state-level singles leaderboard tx_leaderboard = await client.get_leaderboard( category="singles", scope="state", state="TX", ) # Get 50+ age bracket senior_leaderboard = await client.get_leaderboard( age_bracket="50+", verified_only=True, ) for player in leaderboard["players"]: print(f"#{player['rank']} {player['displayName']}: {player['rating']}")
- async get_player_rank(player_id, *, category='doubles', age_bracket='open', scope='global', state=None, city=None, club_id=None, context_size=5)[source]¶
Get a specific player’s rank on the leaderboard.
Requires API Key Scope:
leaderboard:readorread- Parameters:
player_id (
str) – External player ID (vair_mem_xxx format).category (
str(default:'doubles')) – Rating category (default: “doubles”).age_bracket (
str(default:'open')) – Age bracket (default: “open”).scope (
str(default:'global')) – Geographic scope (default: “global”).state (
Optional[str] (default:None)) – State code for state scope.city (
Optional[str] (default:None)) – City name for city scope.club_id (
Optional[str] (default:None)) – Club ID for club scope.context_size (
int(default:5)) – Number of nearby players to include (default: 5).
- Return type:
- Returns:
Dict with rank, percentile, and nearby players.
Example:
rank = await client.get_player_rank( "vair_mem_xxx", category="doubles", context_size=5, ) print(f"Rank: #{rank['rank']} (top {rank['percentile']}%)") print(f"Points to next rank: {rank.get('pointsToNextRank')}") # Show nearby players for nearby in rank["nearbyPlayers"]: print(f"#{nearby['rank']} {nearby['displayName']}")
- async get_leaderboard_categories()[source]¶
Get available leaderboard categories and brackets.
Requires API Key Scope:
leaderboard:readorread- Return type:
- Returns:
Dict with categories, ageBrackets, and scopes.
Example:
categories = await client.get_leaderboard_categories() print("Categories:", [c["name"] for c in categories["categories"]]) print("Age Brackets:", [b["name"] for b in categories["ageBrackets"]])
Models¶
Vairified SDK Models
Rich model classes with methods for easy API interaction.
- class vairified.models.RatingSplit[source]¶
Bases:
objectA single rating split with metadata.
- Variables:
rating – The rating value.
abbr – Abbreviation (e.g., “VG”, “50+”).
date_played – Date of last match in this category.
- Parameters:
- class vairified.models.RatingSplits[source]¶
Bases:
objectRating breakdown by category.
Access ratings by category name (e.g., “open”, “50_and_up”) or use convenience properties for common categories.
- Variables:
splits – Dict mapping category names to RatingSplit objects.
- Parameters:
splits (
dict[str,RatingSplit] (default:<factory>))
- splits: dict[str, RatingSplit]¶
- classmethod from_dict(data)[source]¶
Create from API response dict.
- __init__(splits=<factory>)¶
- Parameters:
splits (
dict[str,RatingSplit] (default:<factory>))- Return type:
None
- class vairified.models.Player[source]¶
Bases:
objectA player in the Vairified system.
From public search, only limited data is available (display name, location, rating). For full profile data, use
Vairified.get_member()with OAuth consent.- Variables:
id – External player ID (vair_mem_xxx format).
display_name – Display name (First Name + Last Initial from search).
first_name – Player’s first name (only from connected member).
last_name – Player’s last name (only from connected member).
rating – Primary/overall rating (2.0-8.0).
is_vairified – Whether player is verified.
is_connected – Whether player has connected to your app.
rating_splits – Ratings by category (only from connected member).
city – City.
state – State code.
country – Country code.
- Parameters:
id (
str)rating (
float)is_vairified (
bool(default:False))is_connected (
bool(default:False))rating_splits (
RatingSplits(default:<factory>))
- rating_splits: RatingSplits¶
- classmethod from_dict(data, client=None)[source]¶
Create from API response dict.
Handles both search (limited data) and member (full data) formats.
- __init__(id, rating, display_name=None, first_name=None, last_name=None, is_vairified=False, is_connected=False, rating_splits=<factory>, city=None, state=None, country=None, _client=None)¶
- Parameters:
id (
str)rating (
float)is_vairified (
bool(default:False))is_connected (
bool(default:False))rating_splits (
RatingSplits(default:<factory>))
- Return type:
None
- class vairified.models.Member[source]¶
Bases:
PlayerA member with full profile access (requires OAuth connection).
Extends
Playerwith additional profile data and methods. Only accessible for players who have connected their account via OAuth.- Variables:
email – Email address (only if profile:email scope granted).
granted_scopes – List of scopes the player granted to your app.
- Parameters:
id (
str)rating (
float)is_vairified (
bool(default:False))is_connected (
bool(default:False))rating_splits (
RatingSplits(default:<factory>))
- async refresh()[source]¶
Refresh member data from API.
- Return type:
- Returns:
Updated Member instance (self).
- Raises:
RuntimeError – If not connected to client.
- __init__(id, rating, display_name=None, first_name=None, last_name=None, is_vairified=False, is_connected=False, rating_splits=<factory>, city=None, state=None, country=None, _client=None, email=None, granted_scopes=<factory>)¶
- Parameters:
id (
str)rating (
float)is_vairified (
bool(default:False))is_connected (
bool(default:False))rating_splits (
RatingSplits(default:<factory>))
- Return type:
None
- class vairified.models.Match[source]¶
Bases:
objectA match to submit to the Vairified Partner API.
For doubles matches, provide two player IDs per team. For singles, provide one player ID per team.
- Variables:
event – Event/tournament name (required).
bracket – Bracket/division name (required).
date – Match date and time (required).
team1 – Tuple of (player1_id, player2_id) or just (player1_id,) for singles.
team2 – Tuple of (player1_id, player2_id) or just (player1_id,) for singles.
scores – List of (team1_score, team2_score) tuples for each game.
match_type – Match type (e.g., “SIDEOUT”, “RALLY”).
source – Match source (e.g., “CLUB”, “TOURNAMENT”).
location – Match location (optional).
identifier – Unique match identifier (auto-generated if not provided).
Example:
# Doubles match: 11-9, 11-7 match = Match( event="Weekly League", bracket="4.0 Doubles", date=datetime.now(), team1=("player1_id", "player2_id"), team2=("player3_id", "player4_id"), scores=[(11, 9), (11, 7)], ) # Singles match: 11-8, 9-11, 11-6 match = Match( event="Club Singles", bracket="Open Singles", date=datetime.now(), team1=("player1_id",), team2=("player2_id",), scores=[(11, 8), (9, 11), (11, 6)], )
- Parameters:
- class vairified.models.RatingUpdate[source]¶
Bases:
objectA rating change notification.
- Variables:
id – External player ID (vair_mem_xxx format).
member_name – Member name.
previous_rating – Rating before change.
new_rating – Rating after change.
changed_at – When the change occurred.
rating_splits – Updated rating splits.
- Parameters:
- rating_splits: RatingSplits¶
- classmethod from_dict(data, client=None)[source]¶
Create from API response dict.
- Parameters:
- Return type:
- Returns:
RatingUpdate instance.
- async get_member()[source]¶
Fetch the member associated with this update.
- Return type:
- Returns:
Member object.
- Raises:
RuntimeError – If not connected to client.
- __init__(id, previous_rating, new_rating, changed_at, member_name=None, rating_splits=<factory>, _client=None)¶
- class vairified.models.MatchResult[source]¶
Bases:
objectResult of a match submission.
- Variables:
success – Whether submission succeeded.
num_matches – Number of matches processed.
num_games – Number of games recorded.
dry_run – Whether this was a dry-run (validation only).
message – Human-readable result message.
errors – List of validation/processing errors.
- Parameters:
- class vairified.models.SearchResults[source]¶
Bases:
objectPaginated search results.
Supports iteration and async pagination.
- Variables:
players – List of Player objects.
total – Total matching players.
page – Current page number.
limit – Results per page.
- Parameters:
- async next_page()[source]¶
Fetch next page of results.
- Return type:
- Returns:
SearchResults for the next page.
- Raises:
RuntimeError – If not connected to client.
StopIteration – If no more pages.
OAuth¶
Vairified OAuth Helpers
Utilities for implementing the “Connect with Vairified” OAuth flow.
- class vairified.oauth.OAuthConfig[source]¶
Bases:
objectOAuth configuration for a partner application.
- Variables:
api_key – Partner API key.
redirect_uri – Your application’s callback URL.
base_url – Vairified API base URL.
- Parameters:
- class vairified.oauth.AuthorizationResponse[source]¶
Bases:
objectResponse from starting an OAuth authorization.
- Variables:
authorization_url – Full URL to redirect the user to.
code – Authorization code (for internal tracking).
state – CSRF state parameter.
- Parameters:
- class vairified.oauth.TokenResponse[source]¶
Bases:
objectResponse from exchanging an authorization code for tokens.
- Variables:
access_token – Access token for API requests.
refresh_token – Refresh token for obtaining new access tokens.
expires_in – Token expiration in seconds.
scope – Granted scopes.
player_id – Connected player’s external ID.
- Parameters:
- vairified.oauth.get_authorization_url(config, scopes=None, state=None)[source]¶
Build the URL to redirect users to for OAuth authorization.
This is a helper for building the URL manually. In most cases, you should use the Vairified client’s OAuth methods instead.
- Parameters:
- Return type:
- Returns:
URL to redirect the user to.
Example:
config = OAuthConfig( api_key="vair_pk_xxx", redirect_uri="https://myapp.com/oauth/callback", ) url = get_authorization_url(config, scopes=["profile:read", "rating:read"]) # Redirect user to this URL
Errors¶
Vairified SDK Errors
Custom exception classes for API errors.
- exception vairified.errors.VairifiedError[source]¶
Bases:
ExceptionBase exception for Vairified API errors.
- Variables:
message – Error message.
status_code – HTTP status code (if applicable).
response – Raw response body (if available).
- Parameters:
- exception vairified.errors.RateLimitError[source]¶
Bases:
VairifiedErrorRaised when rate limit is exceeded.
- Variables:
retry_after – Seconds to wait before retrying.
- Parameters:
- exception vairified.errors.AuthenticationError[source]¶
Bases:
VairifiedErrorRaised when authentication fails.
Typically means the API key is invalid or expired.
- Parameters:
message (
str(default:'Invalid API key'))
- exception vairified.errors.NotFoundError[source]¶
Bases:
VairifiedErrorRaised when a resource is not found.
Typically means the requested member/player doesn’t exist.
- Parameters:
message (
str(default:'Resource not found'))
- exception vairified.errors.ValidationError[source]¶
Bases:
VairifiedErrorRaised when request validation fails.
Check the response body for details on which fields failed validation.
- Parameters:
message (
str(default:'Validation error'))
- exception vairified.errors.OAuthError[source]¶
Bases:
VairifiedErrorRaised when an OAuth operation fails.
This can occur during authorization, token exchange, refresh, or revocation.
- Variables:
error_code – OAuth error code (e.g., ‘invalid_grant’, ‘expired_token’).
- Parameters: