### Install PeopleDataLabs Python SDK Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md Install the SDK using pip. This is the first step before using any of the SDK's functionalities. ```bash pip install peopledatalabs ``` -------------------------------- ### GET Request Example Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Illustrates how parameters are sent as a query string for GET requests, commonly used by enrichment and retrieval APIs. ```http GET /v5/person/enrich?api_key=...&name=John&email=john@example.com ``` -------------------------------- ### School Cleaner Example Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/pdlpy-client.md Use the school endpoint handler to clean school data. ```python client = PDLPY(api_key="your-api-key") result = client.school.cleaner(name="university of oregon") ``` -------------------------------- ### Initialize Request for GET Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Use this snippet to initialize a Request object for making GET requests. Ensure the correct API key, URL, headers, parameters, and Pydantic validator are provided. The API key will be sent as a query parameter. ```python from peopledatalabs.requests import Request from peopledatalabs.models import AutocompleteModel request = Request( api_key="your-api-key", url="https://api.peopledatalabs.com/v5/autocomplete", headers={ "Accept-Encoding": "gzip", "Content-Type": "application/json", "User-Agent": "PDL-PYTHON-SDK", }, params={"field": "title", "text": "eng"}, validator=AutocompleteModel ) response = request.get() if response.ok: results = response.json() ``` -------------------------------- ### POST Request Example Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Shows how parameters are sent in the JSON body for POST requests, utilized by search and bulk operation APIs. ```http POST /v5/person/search HTTP/1.1 X-api-key: ... Content-Type: application/json {"query": {...}, "size": 10} ``` -------------------------------- ### Search Job Postings by Salary Range and Industry Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/job-posting-endpoint.md Use this example to find job postings within a specific salary range, currency, and industry. Ensure the PDLPY client is initialized. ```python client = PDLPY(api_key="your-api-key") result = client.job_posting.search( salary_range_min=100000, salary_range_max=150000, salary_currency="USD", salary_period="year", company_industry="technology", size=20 ) if result.ok: jobs = result.json().get('data', []) print(f"Found {len(jobs)}" jobs with salary 100k-150k USD/year) ``` -------------------------------- ### Request.get Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Executes a GET request to the specified API. The API key is sent as a query parameter. It validates parameters, adds the API key, sends the GET request, and returns the raw response object. ```APIDOC ## GET Request ### Description Executes a GET request to the specified API endpoint. The API key is appended to the URL as a query parameter. ### Method GET ### Endpoint [See Request Constructor for URL] ### Parameters #### Path Parameters None #### Query Parameters - **api_key** (str) - Required - Authentication API key for the request. (Appended automatically) - **[other parameters]** (dict) - Required - Request parameters that will be validated against the provided Pydantic model. #### Request Body None ### Request Example ```python from peopledatalabs.requests import Request from peopledatalabs.models import AutocompleteModel request = Request( api_key="your-api-key", url="https://api.peopledatalabs.com/v5/autocomplete", headers={ "Accept-Encoding": "gzip", "Content-Type": "application/json", "User-Agent": "PDL-PYTHON-SDK", }, params={"field": "title", "text": "eng"}, validator=AutocompleteModel ) response = request.get() if response.ok: results = response.json() ``` ### Response #### Success Response (200) - **[response fields]** - Description (Varies based on the API endpoint) #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### GET Requests Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Details on how GET requests are handled, including authentication and parameter transmission for various APIs. ```APIDOC ## GET Requests ### Description Used by Enrichment, Identify, Retrieve, Cleaner, Autocomplete, JobTitle, and IP APIs. Parameters are sent as query string parameters. ### Method GET ### Endpoint /v5/person/enrich ### Parameters #### Query Parameters - **api_key** (string) - Required - API key for authentication. - **name** (string) - Optional - Name parameter for enrichment. - **email** (string) - Optional - Email parameter for enrichment. ### Request Example ``` GET /v5/person/enrich?api_key=...&name=John&email=john@example.com ``` ``` -------------------------------- ### Company Enrichment Example Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/pdlpy-client.md Use the company endpoint handler to enrich company data using a website. ```python client = PDLPY(api_key="your-api-key") result = client.company.enrichment(website="peopledatalabs.com") ``` -------------------------------- ### Location Cleaner Example Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/pdlpy-client.md Use the location endpoint handler to clean location data. ```python client = PDLPY(api_key="your-api-key") result = client.location.cleaner(location="San Francisco, CA") ``` -------------------------------- ### Job Posting Search Example Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/pdlpy-client.md Use the job posting endpoint handler to search for job postings by title role. ```python client = PDLPY(api_key="your-api-key") result = client.job_posting.search(title_role="engineering") ``` -------------------------------- ### Get Autocomplete Suggestions Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/README.md Use the autocomplete API to get suggestions for a given field and text. This is useful for features like search suggestions. Ensure the client is initialized before use. ```python result = client.autocomplete( field="title", text="full", size=10, ) if result.ok: print(result.text) else: print( f"Status: {result.status_code}" f"\nReason: {result.reason}" f"\nMessage: {result.json()['error']['message']}" ) ``` -------------------------------- ### Example JSON Response Structure Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Illustrates the typical structure of a successful JSON response from the People Data Labs API. ```json { "status": 200, "data": { "id": "qEnOZ5Oh0poWnQ1luFBfVw_0000", "name": "John Doe", "emails": ["john@example.com"], "phone_numbers": ["415-123-4567"], "...": "..." } } ``` -------------------------------- ### Person Enrichment Example Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/pdlpy-client.md Use the person endpoint handler to enrich person data using a phone number. ```python client = PDLPY(api_key="your-api-key") result = client.person.enrichment(phone="4155688415") ``` -------------------------------- ### Get URL for API Endpoint Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/endpoint-base.md Demonstrates how to use the get_url method to construct the full URL for a specific API endpoint like 'enrich' or 'search'. ```python from peopledatalabs.endpoints import Endpoint endpoint = Endpoint( api_key="your-api-key", base_path="https://api.peopledatalabs.com/v5", section="person" ) url = endpoint.get_url("enrich") # Returns: https://api.peopledatalabs.com/v5/person/enrich url = endpoint.get_url("search") # Returns: https://api.peopledatalabs.com/v5/person/search ``` -------------------------------- ### Enrich Person Data by Name and Location Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/person-endpoint.md Example of enriching person data using both name and location parameters. ```python result = client.person.enrichment( name="Jane Smith", location="New York, NY" ) ``` -------------------------------- ### Valid Methods per Endpoint Example Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/errors.md Provides a reference for valid methods available on different endpoints within the People Data Labs Python SDK. This helps in avoiding InvalidEndpointError by ensuring correct method calls. ```python from peopledatalabs import PDLPY client = PDLPY(api_key="your-api-key") # Person endpoint methods client.person.enrichment(**params) # Valid client.person.identify(**params) # Valid client.person.bulk(**params) # Valid client.person.search(**params) # Valid client.person.retrieve(person_id) # Valid client.person.changelog(**params) # Valid # Company endpoint methods client.company.enrichment(**params) # Valid client.company.bulk(**params) # Valid client.company.search(**params) # Valid client.company.cleaner(**params) # Valid # JobPosting endpoint methods client.job_posting.search(**params) # Valid # Location endpoint methods client.location.cleaner(**params) # Valid # School endpoint methods client.school.cleaner(**params) # Valid # Top-level PDLPY methods client.autocomplete(**params) # Valid client.job_title(**params) # Valid client.ip(**params) # Valid ``` -------------------------------- ### Autocomplete API Call Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/pdlpy-client.md Use this snippet to get autocomplete suggestions for a specified field. Ensure you have initialized the PDLPY client with your API key. ```python client = PDLPY(api_key="your-api-key") result = client.autocomplete(field="title", text="full", size=10) if result.ok: print(result.json()) else: print(f"Error: {result.status_code} - {result.reason}") ``` -------------------------------- ### Clean Company Data Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/cleaner-endpoints.md Access the company cleaner via the `client.company.cleaner` method to clean and standardize company names. This example demonstrates cleaning a raw company name string. ```python client = PDLPY(api_key="your-api-key") result = client.company.cleaner( name="peOple DaTa LabS" ) ``` -------------------------------- ### Initialize PDLPY Client Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/pdlpy-client.md Demonstrates various ways to initialize the PDLPY client, including for production, sandbox, custom base paths, and with custom log levels. ```python from peopledatalabs import PDLPY # Production API client = PDLPY(api_key="your-api-key") # Sandbox API sandbox_client = PDLPY(api_key="your-api-key", sandbox=True) # Custom base path client = PDLPY( api_key="your-api-key", base_path="https://custom.api.endpoint/", version="v5" ) # With custom log level client = PDLPY(api_key="your-api-key", log_level="DEBUG") ``` -------------------------------- ### Initialize PDLPY Client (Minimal Production) Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/configuration.md Use this minimal configuration for basic authentication with the production API. Ensure your API key is valid. ```python from peopledatalabs import PDLPY client = PDLPY(api_key="your-api-key") ``` -------------------------------- ### Initialize Sandbox Client Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md Instantiate a client for the sandbox environment by setting the 'sandbox' parameter to True and providing a sandbox API key. ```python sandbox_client = PDLPY(api_key="sandbox-key", sandbox=True) ``` -------------------------------- ### Initialize Client (v3.X.X) Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md Before v4.X.X, the PDLPY client automatically loaded the API key from the environment. ```python import os # PDL_API_KEY automatically loaded from environment client = PDLPY() ``` -------------------------------- ### Initialize Client (v4.X.X+) Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md From v4.X.X onwards, the API key must be explicitly passed to the PDLPY constructor. Environment variable auto-loading was removed. ```python import os api_key = os.environ.get('PDL_API_KEY') client = PDLPY(api_key=api_key) ``` -------------------------------- ### Import Cleaner Endpoints and Initialize Client Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/cleaner-endpoints.md Import the necessary classes for company, location, and school cleaners, and initialize the PDLPY client with your API key. Access cleaner endpoints via client properties. ```python from peopledatalabs.endpoints.company import Company from peopledatalabs.endpoints.location import Location from peopledatalabs.endpoints.school import School from peopledatalabs.main import PDLPY client = PDLPY(api_key="your-api-key") # Access via client properties company_cleaner = client.company.cleaner(**params) location_cleaner = client.location.cleaner(**params) school_cleaner = client.school.cleaner(**params) ``` -------------------------------- ### Get IP Enrichment Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/README.md Enriches an IP address with associated location and network information. ```APIDOC ## Get IP Enrichment ### Description Enriches an IP address with associated location and network information. ### Method POST (inferred from SDK usage) ### Endpoint /v2/ip ### Parameters #### Request Body - **ip** (string) - Required - The IP address to enrich. ### Request Example ```python result = client.ip( ip="72.212.42.228", ) ``` ### Response #### Success Response (200) - **ip_address** (object) - The enriched IP address data. #### Response Example (Response structure not explicitly defined in source, but typically a JSON object with IP enrichment details.) ``` -------------------------------- ### Get Job Title Enrichment Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/README.md Enriches a given job title with additional information. ```APIDOC ## Get Job Title Enrichment ### Description Enriches a given job title with additional information. ### Method POST (inferred from SDK usage) ### Endpoint /v2/job_title ### Parameters #### Request Body - **job_title** (string) - Required - The job title to enrich. ### Request Example ```python result = client.job_title( job_title="data scientist", ) ``` ### Response #### Success Response (200) - **job_title** (object) - The enriched job title data. #### Response Example (Response structure not explicitly defined in source, but typically a JSON object with enriched job title details.) ``` -------------------------------- ### Import Person Endpoint and PDLPY Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/person-endpoint.md Demonstrates how to import the necessary classes and initialize the PDLPY client to access the person endpoint. ```python from peopledatalabs.endpoints.person import Person from peopledatalabs.main import PDLPY # Access via client client = PDLPY(api_key="your-api-key") person_endpoint = client.person ``` -------------------------------- ### School Cleaner Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md Cleans and standardizes school names. Supports GET requests to the /school/clean endpoint. ```APIDOC ## GET /school/clean ### Description Clean school name. ### Method GET ### Endpoint /school/clean ``` -------------------------------- ### Location Cleaner Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md Cleans and standardizes location strings. Supports GET requests to the /location/clean endpoint. ```APIDOC ## GET /location/clean ### Description Clean location string. ### Method GET ### Endpoint /location/clean ``` -------------------------------- ### Initialize PDLPY Client Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/INDEX.md Initialize the PDLPY client for production or sandbox environments using your API key. ```python from peopledatalabs import PDLPY # Production client = PDLPY(api_key="your-key") # Sandbox client = PDLPY(api_key="your-key", sandbox=True) ``` -------------------------------- ### Company Cleaner Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md Cleans and standardizes company names. Supports GET requests to the /company/clean endpoint. ```APIDOC ## GET /company/clean ### Description Clean company name. ### Method GET ### Endpoint /company/clean ``` -------------------------------- ### Initialize PDLPY Client Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/README.md Create an instance of the PDLPY client by providing your API key. This client is used to make requests to People Data Labs APIs. ```python from peopledatalabs import PDLPY # specify your API key client = PDLPY( api_key="YOUR API KEY", ) ``` -------------------------------- ### Initialize PDLPY Client (Custom Base Path) Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/configuration.md Specify a custom API base URL and version when initializing the client. This overrides the default production URL. ```python from peopledatalabs import PDLPY client = PDLPY( api_key="your-api-key", base_path="https://custom.api.example.com/", version="v5" ) ``` -------------------------------- ### Enrich Person Data by Phone Number Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/person-endpoint.md Example of using the person enrichment API with a phone number. ```python result = client.person.enrichment(phone="4155688415") ``` -------------------------------- ### Initialize PDLPY Client (Custom Version) Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/configuration.md Set a specific API version for the client. The version string must conform to the pattern '^v[0-9]$'. ```python from peopledatalabs import PDLPY client = PDLPY( api_key="your-api-key", version="v4" # Must match pattern ^v[0-9]$ ) ``` -------------------------------- ### Initialize PDLPY Client Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/pdlpy-client.md Instantiate the PDLPY client with your API key. This client is used to access all API endpoints. ```python client = PDLPY(api_key="your-api-key") ``` -------------------------------- ### Python: Check Headers for Rate Limit Info Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Demonstrates how to access response headers to check for rate limit information, specifically the 'X-RateLimit-Remaining' header. ```python from peopledatalabs import PDLPY client = PDLPY(api_key="your-api-key") response = client.person.enrichment(name="John Doe") # Rate limit headers (if provided by API) if 'X-RateLimit-Remaining' in response.headers: remaining = response.headers['X-RateLimit-Remaining'] print(f"Remaining requests: {remaining}") ``` -------------------------------- ### Initialize PDLPY Client (Debug Logging) Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/configuration.md Enable debug logging for the PDLPY client session by setting the log_level parameter. This can help in diagnosing issues. ```python from peopledatalabs import PDLPY client = PDLPY( api_key="your-api-key", log_level="DEBUG" ) ``` -------------------------------- ### Initialize PDLPY Client (Sandbox Mode) Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/configuration.md Configure the client to use the sandbox API endpoint by setting the sandbox parameter to True. This is useful for testing without affecting production data. ```python from peopledatalabs import PDLPY sandbox_client = PDLPY(api_key="your-sandbox-key", sandbox=True) ``` -------------------------------- ### Person Retrieve Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md Retrieves a person's profile by their unique PDL ID. Supports GET requests to the /person/retrieve/{id} endpoint. ```APIDOC ## GET /person/retrieve/{id} ### Description Get person by PDL ID. ### Method GET ### Endpoint /person/retrieve/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique PDL ID of the person. ``` -------------------------------- ### Initialize PDLPY Client with API Key Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/configuration.md In SDK versions 4.X.X and later, the API key must be explicitly passed to the PDLPY constructor. This snippet shows how to retrieve the API key from an environment variable and initialize the client, raising an error if the variable is not set. ```python import os from peopledatalabs import PDLPY # ❌ This will NOT auto-load from PDL_API_KEY environment variable # API key must be passed explicitly api_key = os.environ.get('PDL_API_KEY') if api_key: client = PDLPY(api_key=api_key) else: raise ValueError("PDL_API_KEY environment variable not set") ``` -------------------------------- ### Get Autocomplete Suggestions Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/README.md Retrieves autocomplete suggestions for a given field and text input. Useful for providing real-time suggestions in search interfaces. ```APIDOC ## Get Autocomplete Suggestions ### Description Retrieves autocomplete suggestions for a given field and text input. Useful for providing real-time suggestions in search interfaces. ### Method POST (inferred from SDK usage) ### Endpoint /v2/autocomplete ### Parameters #### Query Parameters - **field** (string) - Required - The field to get suggestions for (e.g., 'title'). - **text** (string) - Required - The text to search for. - **size** (integer) - Optional - The number of suggestions to return. ### Request Example ```python result = client.autocomplete( field="title", text="full", size=10, ) ``` ### Response #### Success Response (200) - **data** (list) - A list of autocomplete suggestions. #### Response Example (Response structure not explicitly defined in source, but typically a JSON object containing a list of suggestions.) ``` -------------------------------- ### Enable Sandbox Mode Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/README.md To enable sandbox usage, set the sandbox flag to True when initializing PDLPY. ```python PDLPY(sandbox=True) ``` -------------------------------- ### Import Company Endpoint and PDLPY Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/company-endpoint.md Import necessary classes from the SDK and initialize the PDLPY client with your API key to access the company endpoint. ```python from peopledatalabs.endpoints.company import Company from peopledatalabs.main import PDLPY # Access via client client = PDLPY(api_key="your-api-key") company_endpoint = client.company ``` -------------------------------- ### Handling a 429 Too Many Requests Error Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Provides an example of detecting a rate limiting error and implementing a basic waiting mechanism before retrying. ```python from peopledatalabs import PDLPY import time client = PDLPY(api_key="your-api-key") # Too many requests response = client.person.enrichment(name="John Doe") if response.status_code == 429: # Implement exponential backoff wait_time = 5 print(f"Rate limited. Waiting {wait_time} seconds...") time.sleep(wait_time) ``` -------------------------------- ### autocomplete Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/pdlpy-client.md Calls PeopleDataLabs' autocomplete API to get suggestions for a specified field based on provided text. It allows for customization of the number of results and formatting. ```APIDOC ## autocomplete ### Description Calls PeopleDataLabs' autocomplete API. Returns autocomplete suggestions for a specified field. ### Method POST ### Endpoint /v2/autocomplete ### Parameters #### Query Parameters - **field** (FieldEnum) - Required - The field to autocomplete. Valid values: all_location, class, company, country, industry, location, location_name, major, region, role, school, sub_role, skill, title, website. - **text** (str) - Optional - The text to autocomplete. - **size** (int) - Optional - Number of results to return (1-100). - **pretty** (bool) - Optional - If True, returns formatted JSON response. - **titlecase** (bool) - Optional - If True, applies title case formatting to response. ### Request Example ```python client = PDLPY(api_key="your-api-key") result = client.autocomplete(field="title", text="full", size=10) if result.ok: print(result.json()) else: print(f"Error: {result.status_code} - {result.reason}") ``` ### Response #### Success Response (200) - **data** (list) - A list of autocomplete suggestions. #### Response Example ```json { "data": [ {"name": "Software Engineer", "field": "title"}, {"name": "Full Stack Developer", "field": "title"} ] } ``` ### Error Handling - **EmptyParametersException**: No parameters provided to the method. - **400 Bad Request**: Invalid parameters or request format. - **401 Unauthorized**: Invalid API key. - **404 Not Found**: Resource not found. - **500 Internal Server Error**: Server error. ``` -------------------------------- ### Import JobPosting Endpoint and PDLPY Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/job-posting-endpoint.md Import the JobPosting class and PDLPY for accessing the API. Instantiate PDLPY with your API key and access the job_posting endpoint. ```python from peopledatalabs.endpoints.job_posting import JobPosting from peopledatalabs.main import PDLPY # Access via client client = PDLPY(api_key="your-api-key") job_posting_endpoint = client.job_posting ``` -------------------------------- ### PDLPY Client Initialization Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/pdlpy-client.md Instantiate the PDLPY client with your API key to interact with the People Data Labs API. Optional parameters allow for custom base paths, API versions, logging levels, and sandbox usage. ```APIDOC ## Class: PDLPY ### Description Main client class for interacting with the People Data Labs API. All methods derive from instantiation of this class. ### Constructor ```python PDLPY( api_key: str, base_path: HttpUrl = None, version: str = "v5", log_level: str = None, sandbox: bool = False ) ``` #### Parameters - **api_key** (str) - Required - The authentication API key for API calls. Must not be None. - **base_path** (HttpUrl) - Optional - PeopleDataLabs' API base URL. If None, defaults to production URL + version. - **version** (str) - Optional - PeopleDataLabs' API version. Used only if base_path is None. Must match pattern `^v[0-9]$`. - **log_level** (str) - Optional - The logger level (e.g., "DEBUG", "INFO", "WARNING"). If provided, overrides global log level. - **sandbox** (bool) - Optional - If True, uses sandbox API endpoint instead of production. Overrides base_path. ``` -------------------------------- ### Get IP Enrichment Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/README.md Enrich an IP address to retrieve associated location and organization data. This is useful for analytics and security. Note the specific formatting for error messages. ```python result = client.ip( ip="72.212.42.228", ) if result.ok: print(result.text) else: print( f"Status: {result.status_code};" f"\nReason: {result.reason};" f"\nMessage: {result.json()['error']['message']};" ) ``` -------------------------------- ### Endpoint Class Constructor Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/endpoint-base.md Illustrates the instantiation of the Endpoint class with API key, base path, and an optional section. ```python from peopledatalabs.endpoints import Endpoint endpoint = Endpoint( api_key="your-api-key", base_path="https://api.peopledatalabs.com/v5", section="person" ) ``` -------------------------------- ### Basic Usage of PeopleDataLabs Python SDK Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md Initialize the client with your API key and perform basic enrichment for persons, companies, and job postings. Ensure you handle the response to check for success before processing the data. ```python from peopledatalabs import PDLPY # Initialize client client = PDLPY(api_key="your-api-key") # Person enrichment result = client.person.enrichment(email="john@example.com") if result.ok: person = result.json() print(person) # Company enrichment result = client.company.enrichment(website="example.com") if result.ok: company = result.json() print(company) # Job posting search result = client.job_posting.search(title_role="engineering", is_active=True) if result.ok: jobs = result.json() print(f"Found {jobs.get('total')}"jobs) ``` -------------------------------- ### Enrich Person Data by Email Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/person-endpoint.md Example of using the person enrichment API with an email address. Ensure the 'pretty' parameter is set to True for formatted JSON output. ```python client = PDLPY(api_key="your-api-key") # Enrich by email result = client.person.enrichment(email="john.doe@example.com", pretty=True) ``` -------------------------------- ### Search Companies with SQL Query Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/company-endpoint.md This snippet demonstrates how to search for companies using a SQL query. It requires either 'query' or 'sql' to be provided. The 'size' parameter limits the number of returned companies. ```python client = PDLPY(api_key="your-api-key") # SQL query sql = ( "SELECT * FROM company" " WHERE tags='big data'" " AND industry='financial services'" " AND location.country='united states';" ) result = client.company.search( sql=sql, size=10, pretty=True ) if result.ok: data = result.json() print(f"Found {data.get('total')} companies") ``` -------------------------------- ### Retrieve Person Data Changelog Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/README.md Get a changelog of person data updates between two specified versions. Allows filtering by type of change (e.g., 'updated'). Includes error handling. ```python result = client.person.changelog( origin_version="30.2", target_version="31.0", type="updated", ) if result.ok: print(result.text) else: print( f"Status: {result.status_code}" f"\nReason: {result.reason}" f"\nMessage: {result.json()['error']['message']}" ) ``` -------------------------------- ### Access Global SDK Settings Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/configuration.md Demonstrates how to import and access global settings attributes like base path, API version, sandbox base path, and SDK version from the peopledatalabs.settings module. ```python from peopledatalabs.settings import settings print(settings.base_path) # https://api.peopledatalabs.com/ print(settings.version) # v5 print(settings.sandbox_base_path) # https://sandbox.api.peopledatalabs.com/ print(settings.sdk_version) # 6.4.13 ``` -------------------------------- ### PDLPY Class and Top-Level Methods Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/FILE_MANIFEST.txt Documentation for the main PDLPY client class, including its constructor, properties, and top-level methods like autocomplete, job_title, and ip. ```APIDOC ## PDLPY Class ### Description The main client class for interacting with the People Data Labs API. It provides access to various data endpoints and utility methods. ### Constructor Parameters - **api_key** (str) - Required - Your People Data Labs API key. - **base_path** (str) - Optional - The base URL for the API. - **version** (str) - Optional - The API version to use. - **log_level** (str) - Optional - The logging level for the SDK. - **sandbox** (bool) - Optional - Whether to use the sandbox environment. ### Properties - **person**: Access to Person-related endpoints. - **company**: Access to Company-related endpoints. - **job_posting**: Access to Job Posting-related endpoints. - **location**: Access to Location-related endpoints. - **school**: Access to School-related endpoints. ### Methods - **autocomplete(params)**: Provides autocomplete suggestions. - **job_title(params)**: Retrieves job title information. - **ip(params)**: Fetches information related to an IP address. ``` -------------------------------- ### Get Job Title Enrichment Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/README.md Enrich a given job title using the job title API. This can provide standardized titles and related information. The API requires a job title string as input. ```python result = client.job_title( job_title="data scientist", ) if result.ok: print(result.text) else: print( f"Status: {result.status_code}" f"\nReason: {result.reason}" f"\nMessage: {result.json()['error']['message']}" ) ``` -------------------------------- ### Import PDLPY Client Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/pdlpy-client.md Import the main PDLPY client class from the peopledatalabs library. ```python from peopledatalabs import PDLPY ``` -------------------------------- ### Custom Timeout Wrapper Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Demonstrates how to wrap SDK calls with a custom timeout using the `requests` library, as the SDK itself does not enforce timeouts. ```python from peopledatalabs import PDLPY import requests client = PDLPY(api_key="your-api-key") try: # No timeout set by SDK; add custom timeout wrapper if needed response = client.person.enrichment(name="John Doe") except requests.Timeout: print("Request timed out") ``` -------------------------------- ### PDLPY Constructor Signature Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/configuration.md Defines the parameters available for initializing the PDLPY client, including API key, base path, version, log level, and sandbox mode. ```python PDLPY( api_key: str, base_path: HttpUrl = None, version: str = "v5", log_level: str = None, sandbox: bool = False ) ``` -------------------------------- ### Handle Common SDK Exceptions Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md Demonstrates how to catch specific exceptions like EmptyParametersException, ValidationError, and InvalidEndpointError when using the SDK. Ensure you import the necessary error types. ```python from peopledatalabs import PDLPY from peopledatalabs.errors import EmptyParametersException, InvalidEndpointError from pydantic_core import ValidationError client = PDLPY(api_key="your-api-key") try: result = client.person.enrichment() # No parameters except EmptyParametersException: print("Must provide at least one parameter") except ValidationError as e: print(f"Invalid parameters: {e}") except InvalidEndpointError as e: print(f"Invalid endpoint: {e}") ``` -------------------------------- ### Request.post Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Executes a POST request to the specified API. The API key is sent in the X-api-key header. It validates parameters, adds the API key to headers, sends the POST request with a JSON body, and returns the raw response object. ```APIDOC ## POST Request ### Description Executes a POST request to the specified API endpoint. The API key is sent in the `X-api-key` header. The request parameters are sent as a JSON body. ### Method POST ### Endpoint [See Request Constructor for URL] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **api_key** (str) - Required - Authentication API key for the request. (Sent as `X-api-key` header) - **[other parameters]** (dict) - Required - Request parameters that will be validated against the provided Pydantic model and sent as JSON body. ### Request Example ```python from peopledatalabs.requests import Request from peopledatalabs.models.person import SearchModel search_query = { "query": { "bool": { "must": [ {"term": {"location_country": "mexico"}} ] } } } request = Request( api_key="your-api-key", url="https://api.peopledatalabs.com/v5/person/search", headers={ "Accept-Encoding": "gzip", "Content-Type": "application/json", "User-Agent": "PDL-PYTHON-SDK", }, params={ "query": search_query, "size": 10 }, validator=SearchModel ) response = request.post() if response.ok: results = response.json() print(f"Found {results.get('total')}" persons) ``` ### Response #### Success Response (200) - **[response fields]** - Description (Varies based on the API endpoint) #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Handling a 401 Unauthorized Error Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Demonstrates how to detect and handle an authentication error caused by an invalid API key. ```python from peopledatalabs import PDLPY client = PDLPY(api_key="invalid-key") response = client.person.enrichment(name="John Doe") print(response.status_code) # 401 print(response.reason) # Unauthorized ``` -------------------------------- ### Search Persons with SQL Query Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/person-endpoint.md This snippet demonstrates how to search for persons using a SQL query. Similar to the Elasticsearch query, you must provide either 'query' or 'sql'. The 'dataset' parameter can be used to specify which data types to include in the results. ```python client = PDLPY(api_key="your-api-key") # SQL query sql = ( "SELECT * FROM person" " WHERE location_country='mexico'" " AND job_title_role='health'" " AND phone_numbers IS NOT NULL;" ) result = client.person.search( sql=sql, size=10, pretty=True, dataset="phone, mobile_phone" ) ``` -------------------------------- ### Search Job Postings using Field-Based Parameters Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/job-posting-endpoint.md This snippet demonstrates searching job postings by directly specifying field parameters. Initialize the PDLPY client with your API key before use. ```python client = PDLPY(api_key="your-api-key") result = client.job_posting.search( title_role="engineering", remote_work_policy="remote", is_active=True, size=10, pretty=True ) if result.ok: data = result.json() print(f"Found {data.get('total')}" active remote engineering jobs) ``` -------------------------------- ### Search Company Data using SQL Query Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/README.md This snippet shows how to search for company data by constructing a SQL query. It allows for flexible filtering and handles response status. ```python sql_query = ( "SELECT * FROM company" " WHERE tags='big data'" " AND industry='financial services'" " AND location.country='united states';" ) data = { "sql": sql_query, "size": 10, "pretty": True, } result = client.company.search(**data) if result.ok: print(result.text) else: print( f"Status: {result.status_code}" f"\nReason: {result.reason}" f"\nMessage: {result.json()['error']['message']}" ) ``` -------------------------------- ### Exception Handling Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md Demonstrates how to implement exception handling for common errors encountered when using the People Data Labs Python SDK. ```APIDOC ## Exception Handling ```python from peopledatalabs import PDLPY from peopledatalabs.errors import EmptyParametersException, InvalidEndpointError from pydantic_core import ValidationError client = PDLPY(api_key="your-api-key") try: result = client.person.enrichment() # No parameters except EmptyParametersException: print("Must provide at least one parameter") except ValidationError as e: print(f"Invalid parameters: {e}") except InvalidEndpointError as e: print(f"Invalid endpoint: {e}") ``` ``` -------------------------------- ### Search Job Postings using Field Parameters Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/README.md This snippet demonstrates searching for job postings by directly providing field parameters. It's a simpler alternative to Elasticsearch queries for basic searches and includes error reporting. ```python data = { "title_role": "engineering", "remote_work_policy": "remote", "is_active": True, "size": 10, "pretty": True, } result = client.job_posting.search(**data) if result.ok: print(result.text) else: print( f"Status: {result.status_code}" f"\nReason: {result.reason}" f"\nMessage: {result.json()['error']['message']}" ) ``` -------------------------------- ### Initialize Request for POST Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Use this snippet to initialize a Request object for making POST requests. The API key is sent in the X-api-key header. Ensure all required parameters, including the Pydantic validator, are correctly configured. ```python from peopledatalabs.requests import Request from peopledatalabs.models.person import SearchModel search_query = { "query": { "bool": { "must": [ {"term": {"location_country": "mexico"}} ] } } } request = Request( api_key="your-api-key", url="https://api.peopledatalabs.com/v5/person/search", headers={ "Accept-Encoding": "gzip", "Content-Type": "application/json", "User-Agent": "PDL-PYTHON-SDK", }, params={ "query": search_query, "size": 10 }, validator=SearchModel ) response = request.post() if response.ok: results = response.json() print(f"Found {results.get('total')} persons") ``` -------------------------------- ### Search Companies with SQL Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/INDEX.md Search for companies using a SQL query and specify the number of results to return. ```python result = client.company.search( sql="SELECT * FROM company WHERE industry='technology'", size=10 ) ``` -------------------------------- ### Endpoint Class Constructor Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/endpoint-base.md Initializes the base Endpoint class with authentication and base path information. The section parameter is used for URL construction. ```APIDOC ## Class: Endpoint ### Constructor ```python Endpoint( api_key: str, base_path: HttpUrl, section: str = None ) ``` #### Parameters - **api_key** (str) - Required - Authentication API key. - **base_path** (HttpUrl) - Required - API base URL (e.g., https://api.peopledatalabs.com/v5). - **section** (str) - Optional - API section prefix (e.g., "person", "company"). Used for URL construction. ``` -------------------------------- ### Configure Request Timeout Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/configuration.md The SDK uses Python's requests library with no timeout (None) by default. This means requests may wait indefinitely. This behavior is configured in the requests module. ```python # In src/peopledatalabs/requests.py requests.get(self.url, params=self.params, headers=self.headers, timeout=None) requests.post(self.url, json=self.params, headers=self.headers, timeout=None) ``` -------------------------------- ### Python: Check API Response Status Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Demonstrates how to check if an API request was successful using the `response.ok` attribute. Prints the name if successful, or the status code if failed. ```python from peopledatalabs import PDLPY client = PDLPY(api_key="your-api-key") response = client.person.enrichment(name="John Doe") # Use response.ok for simple success check if response.ok: person = response.json() print(f"Found: {person['data']['name']}") else: print(f"Failed: {response.status_code}") ``` -------------------------------- ### Timeouts Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Information on how to handle request timeouts, as the SDK does not set a default timeout. ```APIDOC ## Timeouts ### Description The SDK does not set a default timeout, meaning requests may wait indefinitely. To implement timeouts, you need to wrap SDK calls with a custom timeout mechanism using the `requests` library. ### Usage ```python from peopledatalabs import PDLPY import requests client = PDLPY(api_key="your-api-key") try: # No timeout set by SDK; add custom timeout wrapper if needed response = client.person.enrichment(name="John Doe") except requests.Timeout: print("Request timed out") ``` ``` -------------------------------- ### Search Person Data using SQL Query Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/README.md Search for person data using a SQL-like query. Configures search parameters including the SQL query, result size, and dataset. Includes error handling. ```python sql_query = ( "SELECT * FROM person" " WHERE location_country='mexico'" " AND job_title_role='health'" " AND phone_numbers IS NOT NULL;" ) data = { "sql": sql_query, "size": 10, "pretty": True, "dataset": "phone, mobile_phone", } result = client.person.search(**data) if result.ok: print(result.text) else: print( f"Status: {result.status_code}" f"\nReason: {result.reason}" f"\nMessage: {result.json()['error']['message']}" ) ``` -------------------------------- ### Implement Rate Limit Handling Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md Check for a 429 status code in the response and implement a delay using 'time.sleep()' to handle rate limiting gracefully. ```python import time if response.status_code == 429: print("Rate limited. Waiting...") time.sleep(5) ``` -------------------------------- ### Catching EmptyParametersException Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/errors.md Demonstrates how to catch the EmptyParametersException, which is raised when an API method is invoked without any parameters. Ensure you import the exception from peopledatalabs.errors. ```python from peopledatalabs import PDLPY from peopledatalabs.errors import EmptyParametersException client = PDLPY(api_key="your-api-key") try: result = client.person.enrichment() # No parameters provided except EmptyParametersException: print("Error: enrichment() requires at least one parameter") ``` -------------------------------- ### Request Handling Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/FILE_MANIFEST.txt Information on how the SDK handles API requests, including response processing, error handling, and retry logic. ```APIDOC ## Request Handling ### Description Details the internal mechanisms for handling API requests and responses within the SDK. ### Request Class - **constructor**: Initializes the request handler. - **methods**: `get()`, `post()` for making HTTP requests. ### Response Handling - Attributes for success and error responses. - Formats for success and error response structures. - Best practices for processing responses. ### Error Handling - Structure and parsing of error responses. - Retry logic and rate limiting considerations. - Parameter validation flow. ``` -------------------------------- ### Provide Required Parameters for Search Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/README.md For person search, provide either a 'query' string or an 'sql' query to retrieve data. ```python # For search, provide either query or sql result = client.person.search(sql="SELECT * FROM person LIMIT 10") ``` -------------------------------- ### Python: Use response.text for Debugging Source: https://github.com/peopledatalabs/peopledatalabs-python/blob/main/_autodocs/api-reference/request-handling.md Shows how to print the raw text of an API response when a request fails. This is useful for debugging unexpected errors. ```python from peopledatalabs import PDLPY client = PDLPY(api_key="your-api-key") response = client.person.enrichment(name="John Doe") if not response.ok: # Show raw response for debugging print("Full response:") print(response.text) ```