PerplexiPy


NamePerplexiPy JSON
Version 1.1.3 PyPI version JSON
download
home_pageNone
SummaryPerplexiPy - A robust Perplexity AI API client
upload_time2024-09-15 01:45:48
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseBSD-3
keywords
VCS
bugtrack_url
requirements appdirs click openai prompt_toolkit python-dotenv pyyaml
Travis-CI No Travis.
coveralls test coverage No coveralls.
            % perplexipy(3) Version 1.1.3 | Perplexity AI high level API documentation

Name
====

**PerplexiPy** - Perplexity AI high level library


<img src='https://images2.imgbox.com/57/94/AsI1WSfy_o.png'>


Synopsis
========
```python
client = PerplexityClient() \
print(client.query('What is the meaning of 42?') \
for result in client.queryStreamable('List of all US presidents'): \
    print(result)
```


Description
===========
**PerplexiPy** is 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.

**PerplexiPy** implements 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.

<a href='https://www.perplexity.ai/' target='_blank'>Perplexity AI</a> is 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.  **PerplexiPy** enables the creation of Python
programs and tools that leverage the power of Perplexity AI.


Documentation
=============
These documents encompass all information about **PerplexiPy**:

- This README file, hosted in the **[perplexipy](https://github.com/CIME-Software/perplexipy)** GitHub repository
  project on GitHub and exported to the PyPI project page
- A `man` page autogenerated from this README file, `perplexipy.3`
- The complete **PerplexiPy API reference** on GitHub Pages - https://cime-software.github.io/perplexipy/perplexipy.html
- The <a href='https://github.com/CIME-Software/perplexipy/blob/master/PerplexiPy-tutorial.ipynb' target='_blank'>PerplexiPy-tutorial.ipynb</a> tutorial notebook

The `man` page can be generated from the source distribution using this command:

```bash
make manpage
```

The output will reside in:  `./manpages/perplexipy.3`.  The `man` page 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.


Installation
============
```bash
pip install perplexipy
```

Package information:  https://pypi.org/project/perplexipy

PerplexiPy requires an API key issued by Perplexity.  You may set PERPLEXITY_API_KEY
as an environment variable or use a `.env` file.


API key
=======
Access to the Perplexity API requires a paid subscription and an API key.

Use of `.env` is recommended for storing the private key.  There is an automatic
constant `PERPLEXITY_API_KEY` that gets initialized to the value of a `.env` key
of the same name via the `dotenv` API.  Otherwise, `PERPLEXITY_API_KEY` may
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 during `PerplexityClient` instantiation:

```python
import os

key = os.environ['PERPLEXITY_API_KEY']
client = PerplexityClient(key = key)
print(client.query('Brief answer:  greet the world in Swedish.'))
```


Usage
=====
See the <a href='https://github.com/CIME-Software/perplexipy/blob/master/PerplexiPy-tutorial.ipynb' target='_blank'>PerplexiPy-tutorial.ipynb</a> notebook for a richer example of the API's
capabilities.

In general:

```python
client = PerplexityClient()
result = client.query('Show me how to declare a list in Python')
# result is a string

results = client.queryBatch('Show me different ways of declaring a Python list')
for result in results:
    print(result)
    # results is a tuple of one or more results

results = client.queryStreamable('Tell me why lists are important in programming')
for result in results:
    print(result)
    # results is a long stream of data, served over time.

models = client.models # lists all models supported by Perplexity AI

print('Model names:')
for model in models.keys():
    print(' - %s' % model)

try:
    client.model = 'bogus-LLM-7b'
except PerplexityClientError as e:
    print(e)

client.model = models.keys()[0] # OK
```


Async usage
===========
Not supported at this time.


Interactive usage
=================
PerplexiPy ships with the Codex Playground, an interactive REPL console.  To
run it:

```bash
# In a virtualenv:
pip install -U perplexipy
export PERPLEXITY_API_KEY="your-key-goes-here"
codex repl
```

Full description of Codex Playground and other use cases like streaming API and
CLI argument passing in the [Codex README](https://github.com/CIME-Software/perplexipy/blob/master/codex-README.md).


License
=======
The **PerplexiPy** package, documentation and examples are licensed under the
[BSD-3 open source license](https://github.com/CIME-Software/perplexipy/blob/master/LICENSE.txt).


See also
========
- **codex** - a PerplexiPy command line code explainer
- API documentation:  https://cime-software.github.io/perplexipy
- <a href='https://www.perplexity.ai/' target='_blank'>Perplexity AI</a>
- m0toko:  a Sopel bot plug-in that uses PerplexiPy for providing AI-enhanced
  chatbot functionality:  https://github.com/pr3d4t0r/m0toko
- PyPI:  <a href='https://pipy.org/project/openai' target='_blank'>openai</a>


Caveats
=======
The 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.


Bugs
====
Feature requests and bug reports:

https://github.com/CIME-Software/perplexipy/issues


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "PerplexiPy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "CIME Software Ltd <perplexipy@cime.net>",
    "download_url": null,
    "platform": null,
    "description": "% perplexipy(3) Version 1.1.3 | Perplexity AI high level API documentation\n\nName\n====\n\n**PerplexiPy** - Perplexity AI high level library\n\n\n<img src='https://images2.imgbox.com/57/94/AsI1WSfy_o.png'>\n\n\nSynopsis\n========\n```python\nclient = PerplexityClient() \\\nprint(client.query('What is the meaning of 42?') \\\nfor result in client.queryStreamable('List of all US presidents'): \\\n    print(result)\n```\n\n\nDescription\n===========\n**PerplexiPy** is a high-level, convenience library for interacting with the\nPerplexity API from any Python 3.9+ application.  The library aims to simplify\ninteractions with Perplexity models by encapsulating all the implementation\ndetails of the lower level OpenAI API.  All interaction between the code and\nthis library occurs in the form of string and native Python objects, not\nOpenAPI / Swagger mapped objects.\n\n**PerplexiPy** implements a combination of the Perplexity AI and the\nOpenAI outputs.  API semantics follow the \"literate programming\" workflow,\nand attempt to make the resulting code as simple to follow as possible.\n\n<a href='https://www.perplexity.ai/' target='_blank'>Perplexity AI</a> is an\nAI-powered search engine that uses natural language\nprocessing and machine learning to provide accurate and comprehensive answers to\nend-user queries.  It can be argued that it outperforms OpenAI's offerings in\naccuracy and responsiveness.  **PerplexiPy** enables the creation of Python\nprograms and tools that leverage the power of Perplexity AI.\n\n\nDocumentation\n=============\nThese documents encompass all information about **PerplexiPy**:\n\n- This README file, hosted in the **[perplexipy](https://github.com/CIME-Software/perplexipy)** GitHub repository\n  project on GitHub and exported to the PyPI project page\n- A `man` page autogenerated from this README file, `perplexipy.3`\n- The complete **PerplexiPy API reference** on GitHub Pages - https://cime-software.github.io/perplexipy/perplexipy.html\n- The <a href='https://github.com/CIME-Software/perplexipy/blob/master/PerplexiPy-tutorial.ipynb' target='_blank'>PerplexiPy-tutorial.ipynb</a> tutorial notebook\n\nThe `man` page can be generated from the source distribution using this command:\n\n```bash\nmake manpage\n```\n\nThe output will reside in:  `./manpages/perplexipy.3`.  The `man` page isn't\nincluded in the Python package wheel because there's no accepted standard\ninstallation that's cross-compatible among all supported operating systems and\ndistributions.\n\n\nInstallation\n============\n```bash\npip install perplexipy\n```\n\nPackage information:  https://pypi.org/project/perplexipy\n\nPerplexiPy requires an API key issued by Perplexity.  You may set PERPLEXITY_API_KEY\nas an environment variable or use a `.env` file.\n\n\nAPI key\n=======\nAccess to the Perplexity API requires a paid subscription and an API key.\n\nUse of `.env` is recommended for storing the private key.  There is an automatic\nconstant `PERPLEXITY_API_KEY` that gets initialized to the value of a `.env` key\nof the same name via the `dotenv` API.  Otherwise, `PERPLEXITY_API_KEY` may\nbe handled like any other secret by the implementing team.  This module provides\nno other tools or services for handling the API key.\n\nThis key is used only during `PerplexityClient` instantiation:\n\n```python\nimport os\n\nkey = os.environ['PERPLEXITY_API_KEY']\nclient = PerplexityClient(key = key)\nprint(client.query('Brief answer:  greet the world in Swedish.'))\n```\n\n\nUsage\n=====\nSee the <a href='https://github.com/CIME-Software/perplexipy/blob/master/PerplexiPy-tutorial.ipynb' target='_blank'>PerplexiPy-tutorial.ipynb</a> notebook for a richer example of the API's\ncapabilities.\n\nIn general:\n\n```python\nclient = PerplexityClient()\nresult = client.query('Show me how to declare a list in Python')\n# result is a string\n\nresults = client.queryBatch('Show me different ways of declaring a Python list')\nfor result in results:\n    print(result)\n    # results is a tuple of one or more results\n\nresults = client.queryStreamable('Tell me why lists are important in programming')\nfor result in results:\n    print(result)\n    # results is a long stream of data, served over time.\n\nmodels = client.models # lists all models supported by Perplexity AI\n\nprint('Model names:')\nfor model in models.keys():\n    print(' - %s' % model)\n\ntry:\n    client.model = 'bogus-LLM-7b'\nexcept PerplexityClientError as e:\n    print(e)\n\nclient.model = models.keys()[0] # OK\n```\n\n\nAsync usage\n===========\nNot supported at this time.\n\n\nInteractive usage\n=================\nPerplexiPy ships with the Codex Playground, an interactive REPL console.  To\nrun it:\n\n```bash\n# In a virtualenv:\npip install -U perplexipy\nexport PERPLEXITY_API_KEY=\"your-key-goes-here\"\ncodex repl\n```\n\nFull description of Codex Playground and other use cases like streaming API and\nCLI argument passing in the [Codex README](https://github.com/CIME-Software/perplexipy/blob/master/codex-README.md).\n\n\nLicense\n=======\nThe **PerplexiPy** package, documentation and examples are licensed under the\n[BSD-3 open source license](https://github.com/CIME-Software/perplexipy/blob/master/LICENSE.txt).\n\n\nSee also\n========\n- **codex** - a PerplexiPy command line code explainer\n- API documentation:  https://cime-software.github.io/perplexipy\n- <a href='https://www.perplexity.ai/' target='_blank'>Perplexity AI</a>\n- m0toko:  a Sopel bot plug-in that uses PerplexiPy for providing AI-enhanced\n  chatbot functionality:  https://github.com/pr3d4t0r/m0toko\n- PyPI:  <a href='https://pipy.org/project/openai' target='_blank'>openai</a>\n\n\nCaveats\n=======\nThe code should work with Python 3.7 or later, but it was only tested with\nPython 3.9.16 and later.  Download the package and install it from source if\nsupport for an earlier Python version is required.\n\n\nBugs\n====\nFeature requests and bug reports:\n\nhttps://github.com/CIME-Software/perplexipy/issues\n\n",
    "bugtrack_url": null,
    "license": "BSD-3",
    "summary": "PerplexiPy - A robust Perplexity AI API client",
    "version": "1.1.3",
    "project_urls": {
        "Bug Tracker": "https://github.com/CIME-Software/perplexipy/issues",
        "Documentation": "https://cime-software.github.io/perplexipy/",
        "Source": "https://github.com/CIME-Software/perplexipy",
        "homepage": "https://cime-software.github.io/perplexipy/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1f2581483881577aefe34351b213c049e0cd6f492562cfabd9557cc59fb74b16",
                "md5": "47fbe9b1411229d45b996cdd39f8d2a6",
                "sha256": "287b39139d314425eea5012da4bb4d49d02aee9235ca821b78c1810df3c0a67d"
            },
            "downloads": -1,
            "filename": "PerplexiPy-1.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "47fbe9b1411229d45b996cdd39f8d2a6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 13219,
            "upload_time": "2024-09-15T01:45:48",
            "upload_time_iso_8601": "2024-09-15T01:45:48.841288Z",
            "url": "https://files.pythonhosted.org/packages/1f/25/81483881577aefe34351b213c049e0cd6f492562cfabd9557cc59fb74b16/PerplexiPy-1.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-15 01:45:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "CIME-Software",
    "github_project": "perplexipy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "appdirs",
            "specs": []
        },
        {
            "name": "click",
            "specs": []
        },
        {
            "name": "openai",
            "specs": [
                [
                    ">=",
                    "1.12.0"
                ]
            ]
        },
        {
            "name": "prompt_toolkit",
            "specs": []
        },
        {
            "name": "python-dotenv",
            "specs": []
        },
        {
            "name": "pyyaml",
            "specs": []
        }
    ],
    "lcname": "perplexipy"
}
        
Elapsed time: 2.09349s