Skip to content

Conversation

@subhobhai943
Copy link

Summary

This PR resolves issue #12 by adding the missing country parameter to the search API. The parameter is available in the Perplexity API playground but was missing from the Python SDK.

Changes

🔧 Core Changes

  • Added country parameter to SearchCreateParams - Added the parameter definition with proper typing (Optional[str])
  • Updated both sync and async search methods - Added the country parameter to both SearchResource.create() and AsyncSearchResource.create() methods
  • Added parameter documentation - Added docstring documentation explaining the parameter usage with examples

📚 Documentation & Examples

  • Updated README.md - Added a new section documenting the country parameter with usage examples
  • Created example script - Added examples/search_with_country.py demonstrating both sync and async usage

📝 Files Modified

  • src/perplexity/types/search_create_params.py - Added country parameter definition
  • src/perplexity/resources/search.py - Added country parameter to both sync and async methods
  • README.md - Added documentation section for country parameter
  • examples/search_with_country.py - New example demonstrating usage

Usage

from perplexity import Perplexity

client = Perplexity(api_key="your-api-key")

# Search with country restriction
search = client.search.create(
    query="latest tech news",
    country="US",  # ISO 3166-1 alpha-2 country code
    max_results=5
)

for result in search.results:
    print(f"{result.title}: {result.url}")

Parameter Details

  • Type: Optional[str]
  • Format: ISO 3166-1 alpha-2 country codes (e.g., "US", "GB", "CA", "DE", "FR", "JP", "AU", "IN")
  • Purpose: Restricts search results to content from the specified country
  • Availability: Both synchronous and asynchronous methods

Testing

The fix includes:

  • ✅ Proper type hints for IDE autocomplete and type checking
  • ✅ Documentation with parameter descriptions
  • ✅ Example usage in both sync and async modes
  • ✅ Comprehensive README documentation

Related Issues

Backward Compatibility

This change is fully backward compatible as the country parameter is optional and defaults to omit. Existing code will continue to work without modification.


Note: This parameter was already available in the Perplexity API but was missing from the Python SDK. This PR brings the SDK in line with the actual API capabilities shown in the playground.

Resolves issue perplexityai#12 by adding the missing 'country' parameter
to the search API parameters. This parameter is available in
the Perplexity API playground but was missing from the Python SDK.
Adds the country parameter to both synchronous and asynchronous
search methods with proper type hints and documentation. This
resolves the missing country parameter issue reported in perplexityai#12.
Adds a comprehensive example showing how to use the newly implemented
country parameter in both sync and async modes. Includes documentation
and error handling for better user experience.
Adds a new section documenting the country parameter feature
with examples showing how to restrict search results to specific
countries using ISO 3166-1 alpha-2 country codes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

country parameter is missing

1 participant