Google Cloud Talent API client library for job search and talent management
—
Advanced job search capabilities with text queries, geographic filtering, compensation ranges, commute time calculations, and faceted search with histogram analytics for building sophisticated job search experiences. The search system supports natural language queries, structured filters, and machine learning-powered ranking.
Performs natural language searches across job titles, descriptions, company names, and other textual content with intelligent query processing and ranking.
class JobQuery:
"""Primary search query object for job searches."""
query: str = None # Free text search query (max 255 chars)
companies: List[str] = None # Filter by specific companies (max 20)
location_filters: List[LocationFilter] = None # Geographic filtering (max 5)
job_categories: List[JobCategory] = None # Filter by job categories
employment_types: List[EmploymentType] = None # Filter by employment types
compensation_filter: CompensationFilter = None # Salary range filtering
commute_filter: CommuteFilter = None # Commute time-based filtering
custom_attribute_filter: str = None # SQL-like custom field filtering
publish_time_range: TimestampRange = None # Filter by posting date
excluded_jobs: List[str] = None # Jobs to exclude from resultsUsage Example:
from google.cloud.talent import JobQuery, SearchJobsRequest
# Simple text search
query = JobQuery(query="python software engineer")
search_request = SearchJobsRequest(
parent="projects/my-project/tenants/my-tenant",
job_query=query
)
response = client.search_jobs(search_request)Filters jobs based on location with support for addresses, coordinates, distance radius, and telecommute preferences.
class LocationFilter:
"""Geographic search filtering with flexible location specification."""
address: str = None # Address or location name
region_code: str = None # CLDR country/region code (e.g., "US", "CA")
lat_lng: LatLng = None # Latitude/longitude coordinates
distance_in_miles: float = None # Search radius in miles
telecommute_preference: TelecommutePreference = None # Remote work filtering
class TelecommutePreference(Enum):
"""Telecommute filtering options."""
TELECOMMUTE_PREFERENCE_UNSPECIFIED = 0
TELECOMMUTE_EXCLUDED = 1 # Exclude remote jobs
TELECOMMUTE_ALLOWED = 2 # Include remote jobsUsage Example:
from google.cloud.talent import LocationFilter, LatLng
# Search by address with radius
location_filter = LocationFilter(
address="San Francisco, CA",
distance_in_miles=25.0
)
# Search by coordinates
location_filter_coords = LocationFilter(
lat_lng=LatLng(latitude=37.7749, longitude=-122.4194),
distance_in_miles=15.0
)
# Include remote jobs
location_filter_remote = LocationFilter(
address="San Francisco, CA",
distance_in_miles=50.0,
telecommute_preference=TelecommutePreference.TELECOMMUTE_ALLOWED
)
query = JobQuery(
query="software engineer",
location_filters=[location_filter, location_filter_remote]
)Filters jobs based on salary ranges and compensation structures with support for different time units and compensation types.
class CompensationFilter:
"""Salary and compensation filtering with flexible range specification."""
type_: FilterType = None # Filter type specification
units: List[CompensationUnit] = None # Time units for compensation
range_: CompensationRange = None # Min/max compensation range
include_jobs_with_unspecified_compensation: bool = None # Include jobs without salary info
class FilterType(Enum):
"""Compensation filter types."""
FILTER_TYPE_UNSPECIFIED = 0
UNIT_ONLY = 1 # Filter by compensation unit only
UNIT_AND_AMOUNT = 2 # Filter by unit and amount
ANNUALIZED_BASE_AMOUNT = 3 # Filter by annualized base salary
ANNUALIZED_TOTAL_AMOUNT = 4 # Filter by total compensation
class CompensationRange:
"""Compensation range specification."""
max_compensation: Money = None # Maximum compensation
min_compensation: Money = None # Minimum compensation
class Money:
"""Monetary amount specification."""
currency_code: str = None # ISO 4217 currency code (e.g., "USD")
units: int = None # Integer amount
nanos: int = None # Fractional amount (nano units)Usage Example:
from google.cloud.talent import CompensationFilter, CompensationRange, Money
# Filter by annual salary range
compensation_filter = CompensationFilter(
type_=CompensationFilter.FilterType.ANNUALIZED_BASE_AMOUNT,
range_=CompensationRange(
min_compensation=Money(currency_code="USD", units=80000),
max_compensation=Money(currency_code="USD", units=150000)
)
)
# Filter by hourly rate
hourly_filter = CompensationFilter(
type_=CompensationFilter.FilterType.UNIT_AND_AMOUNT,
units=[CompensationUnit.HOURLY],
range_=CompensationRange(
min_compensation=Money(currency_code="USD", units=50),
max_compensation=Money(currency_code="USD", units=100)
)
)
query = JobQuery(
query="contractor developer",
compensation_filter=hourly_filter
)Filters jobs based on commute time from a starting location using various transportation methods with traffic considerations.
class CommuteFilter:
"""Commute time-based job filtering with transportation options."""
commute_method: CommuteMethod = None # Transportation method
start_coordinates: LatLng = None # Starting location coordinates
travel_duration: Duration = None # Max commute time (up to 1 hour)
allow_imprecise_addresses: bool = None # Allow approximate address matching
road_traffic: RoadTraffic = None # Traffic condition assumption
departure_time: TimeOfDay = None # Departure time for traffic calculation
class CommuteMethod(Enum):
"""Transportation methods for commute calculation."""
COMMUTE_METHOD_UNSPECIFIED = 0
DRIVING = 1 # Personal vehicle
TRANSIT = 2 # Public transportation
WALKING = 3 # Walking
CYCLING = 4 # Bicycle
TRANSIT_ACCESSIBLE = 5 # Accessible public transit
class RoadTraffic(Enum):
"""Traffic condition assumptions."""
ROAD_TRAFFIC_UNSPECIFIED = 0
TRAFFIC_FREE = 1 # No traffic delays
BUSY_HOUR = 2 # Peak traffic conditionsUsage Example:
from google.cloud.talent import CommuteFilter, CommuteMethod, Duration, TimeOfDay
from datetime import timedelta
# 45-minute driving commute with traffic
commute_filter = CommuteFilter(
commute_method=CommuteMethod.DRIVING,
start_coordinates=LatLng(latitude=37.7749, longitude=-122.4194),
travel_duration=Duration(seconds=2700), # 45 minutes
road_traffic=RoadTraffic.BUSY_HOUR,
departure_time=TimeOfDay(hours=8, minutes=30) # 8:30 AM departure
)
# Public transit commute
transit_filter = CommuteFilter(
commute_method=CommuteMethod.TRANSIT,
start_coordinates=LatLng(latitude=37.7749, longitude=-122.4194),
travel_duration=Duration(seconds=3600) # 1 hour max
)
query = JobQuery(
query="software engineer",
commute_filter=commute_filter
)Filters jobs using custom attributes with SQL-like syntax for complex filtering scenarios.
# Custom attribute filter examples
query = JobQuery(
query="data scientist",
custom_attribute_filter='(skills HAS "python" OR skills HAS "r") AND experience_level = "senior"'
)
# Numeric custom attributes
query_numeric = JobQuery(
query="sales",
custom_attribute_filter='quota_target >= 100000 AND territory = "west_coast"'
)Filters jobs based on posting date and other temporal criteria.
from google.cloud.talent import TimestampRange
from google.protobuf.timestamp_pb2 import Timestamp
from datetime import datetime, timedelta
# Jobs posted in the last 7 days
now = datetime.utcnow()
week_ago = now - timedelta(days=7)
time_filter = TimestampRange(
start_time=Timestamp(seconds=int(week_ago.timestamp())),
end_time=Timestamp(seconds=int(now.timestamp()))
)
query = JobQuery(
query="python developer",
publish_time_range=time_filter
)Provides aggregated counts for various job attributes to build faceted search interfaces and analytics dashboards.
class HistogramQuery:
"""Request for faceted search analytics."""
histogram_query: str = None # Facet field to aggregate
class HistogramQueryResult:
"""Histogram results with counts by facet values."""
histogram_query: str = None # Original query
histogram: Dict[str, int] = None # Facet value countsUsage Example:
from google.cloud.talent import HistogramQuery
search_request = SearchJobsRequest(
parent="projects/my-project/tenants/my-tenant",
job_query=JobQuery(query="software engineer"),
histogram_queries=[
HistogramQuery(histogram_query="employment_type"),
HistogramQuery(histogram_query="job_level"),
HistogramQuery(histogram_query="company_size"),
HistogramQuery(histogram_query="job_category")
]
)
response = client.search_jobs(search_request)
# Process histogram results for faceted search UI
for histogram_result in response.histogram_query_results:
print(f"Facet: {histogram_result.histogram_query}")
for facet_value, count in histogram_result.histogram.items():
print(f" {facet_value}: {count} jobs")Configure search behavior with ranking, diversification, and result processing options.
class SearchJobsRequest:
parent: str = None # Tenant resource name
search_mode: SearchMode = None # Search mode
job_query: JobQuery = None # Search query and filters
enable_broadening: bool = None # Enable query broadening for more results
histogram_queries: List[HistogramQuery] = None # Faceted search
job_view: JobView = None # Detail level in results
offset: int = None # Result offset for pagination
page_size: int = None # Page size (max 100 for search)
page_token: str = None # Pagination token
order_by: str = None # Sort order specification
diversification_level: DiversificationLevel = None # Result diversity
custom_ranking_info: CustomRankingInfo = None # Custom ranking factors
disable_keyword_match: bool = None # Disable keyword matching
class SearchMode(Enum):
"""Search mode options."""
SEARCH_MODE_UNSPECIFIED = 0
JOB_SEARCH = 1 # Standard job search
FEATURED_JOB_SEARCH = 2 # Featured jobs only
class DiversificationLevel(Enum):
"""Result diversification levels."""
DIVERSIFICATION_LEVEL_UNSPECIFIED = 0
DISABLED = 1 # No diversification
SIMPLE = 2 # Basic diversificationUsage Example:
# Advanced search with custom ranking and diversification
search_request = SearchJobsRequest(
parent="projects/my-project/tenants/my-tenant",
search_mode=SearchMode.JOB_SEARCH,
job_query=JobQuery(
query="machine learning engineer",
location_filters=[LocationFilter(address="San Francisco, CA", distance_in_miles=30)]
),
enable_broadening=True,
diversification_level=DiversificationLevel.SIMPLE,
order_by="relevance desc",
job_view=JobView.JOB_VIEW_SMALL,
page_size=20
)
response = client.search_jobs(search_request)class SearchJobsResponse:
"""Complete search response with jobs, metadata, and analytics."""
matching_jobs: List[MatchingJob] = None # Jobs with match information
histogram_query_results: List[HistogramQueryResult] = None # Facet results
next_page_token: str = None # Pagination token
location_filters: List[Location] = None # Matched/corrected locations
estimated_total_size: int = None # Estimated total result count
total_size: int = None # Actual total result count (expensive)
metadata: ResponseMetadata = None # Response metadata
broadened_query_jobs_count: int = None # Count of broadened results
spell_correction: SpellCheckResult = None # Query spelling corrections
class MatchingJob:
"""Individual job result with match metadata."""
job: Job = None # Complete job object
job_summary: str = None # Highlighted summary
job_title_snippet: str = None # Highlighted title
search_text_snippet: str = None # Highlighted description excerpt
commute_info: CommuteInfo = None # Commute calculation results# Process search results with highlighting and metadata
for matching_job in response.matching_jobs:
job = matching_job.job
print(f"Title: {matching_job.job_title_snippet or job.title}")
print(f"Company: {job.company}")
print(f"Summary: {matching_job.job_summary}")
# Display commute information if available
if matching_job.commute_info:
commute = matching_job.commute_info
print(f"Commute: {commute.travel_duration} via {commute.commute_method}")
print("---")
# Handle spelling corrections
if response.spell_correction:
if response.spell_correction.corrected_text:
print(f"Did you mean: {response.spell_correction.corrected_text}")Search operations can raise several types of exceptions:
from google.api_core import exceptions
try:
response = client.search_jobs(search_request)
except exceptions.InvalidArgument as e:
# Handle invalid search parameters
print(f"Invalid search query: {e}")
except exceptions.PermissionDenied as e:
# Handle authorization errors
print(f"Access denied: {e}")
except exceptions.ResourceExhausted as e:
# Handle quota limits
print(f"Search quota exceeded: {e}")Common error scenarios:
Install with Tessl CLI
npx tessl i tessl/pypi-google-cloud-talent