Package: perplexipy
% perplexipy(3) Version 0.0.9 | Perplexity AI high level API documentationNamePerplexiPy- Perplexity AI high level librarySynopsisclient=PerplexityClient()\print(client.query('What is the meaning of 42?')\forresultinclient.queryStreamable('List of all US presidents'):\print(result)DescriptionPerplexiPyis a high-level, convenience library for interacting with the
Perplexity API from any Python 3.9+ application.  The library aims to simplify
interactions with Perplexity models by encapsulating all the implementation
details of the lower level OpenAI API.  All interaction between the code and
this library occurs in the form of string and native Python objects, not
OpenAPI / Swagger mapped objects.PerplexiPyimplements a combination of the Perplexity AI and the
OpenAI outputs.  API semantics follow the "literate programming" workflow,
and attempt to make the resulting code as simple to follow as possible.Perplexity AIis an
AI-powered search engine that uses natural language
processing and machine learning to provide accurate and comprehensive answers to
end-user queries.  It can be argued that it outperforms OpenAI's offerings in
accuracy and responsiveness.PerplexiPyenables the creation of Python
programs and tools that leverage the power of Perplexity AI.DocumentationThese documents encompass all information aboutPerplexiPy:This README file, hosted in theperplexipyGitHub repository
project on GitHub and exported to the PyPI project pageAmanpage autogenerated from this README file,perplexipy.3The completePerplexiPy API referenceon GitHub PagesThePerplexiPy-tutorial.ipynbtutorial notebookThemanpage can be generated from the source distribution using this command:makemanpageThe output will reside in:./manpages/perplexipy.3.  Themanpage isn't
included in the Python package wheel because there's no accepted standard
installation that's cross-compatible among all supported operating systems and
distributions.InstallationpipinstallperplexipyPackage information:https://pypi.org/project/perplexipyAPI keyAccess to the Perplexity API requires a paid subscription and an API key.Use of.envis recommended for storing the private key.  There is an automatic
constantPERPLEXITY_API_KEYthat gets initialized to the value of a.envkey
of the same name via thedotenvAPI.  Otherwise,PERPLEXITY_API_KEYmay
be handled like any other secret by the implementing team.  This module provides
no other tools or services for handling the API key.This key is used only duringPerplexityClientinstantiation:importoskey=os.environ['PERPLEXITY_API_KEY']client=PerplexityClient(key=key)print(client.query('Brief answer:  greet the world in Swedish.'))UsageSee thePerplexiPy-tutorial.ipynbnotebook for a richer example of the API's
capabilities.In general:client=PerplexityClient()result=client.query('Show me how to declare a list in Python')# result is a stringresults=client.queryBatch('Show me different ways of declaring a Python list')forresultinresults:print(result)# results is a tuple of one or more resultsresults=client.queryStreamable('Tell me why lists are important in programming')forresultinresults:print(result)# results is a long stream of data, served over time.models=client.models# lists all models supported by Perplexity AIprint('Model names:')formodelinmodels.keys():print(' -%s'%model)try:client.model='bogus-LLM-7b'exceptPerplexityClientErrorase:print(e)client.model=models.keys()[0]# OKAsync usageNot supported at this time.LicenseThePerplexiPypackage, documentation and examples are licensed under theBSD-3 open source license.See alsoPyPI:openaiPerplexity AICaveatsThe code should work with Python 3.7 or later, but it was only tested with
Python 3.9.16 and later.  Download the package and install it from source if
support for an earlier Python version is required.BugsFeature requests and bug reports:https://github.com/CIME-Software/perplexipy/issues