context-python


Namecontext-python JSON
Version 0.14.0 PyPI version JSON
download
home_pageNone
SummaryPython SDK for the Context API
upload_time2024-04-30 12:27:59
maintainerNone
docs_urlNone
authorAlex Gamble
requires_python<4.0,>=3.10
licenseLICENSE.md
keywords context api sdk
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Context Python Library

[![PyPI version](https://badge.fury.io/py/context-python.svg)](https://badge.fury.io/py/context-python)

The Context Python library provides a convenient way to interface with the Context APIs. We include pre-defined classes and operations to interact with API resources.

## Installation

```
pip install --upgrade context-python
```

## Usage

The library needs to be configured with your Context API key, which is available in the [Context Settings Dashboard](https://go.getcontext.ai/settings).

### Synchronous Example

```python
import getcontext
from getcontext.generated.models import Conversation, Message, MessageRole, Rating
from getcontext.token import Credential
import os

token = os.environ.get("GETCONTEXT_TOKEN")

c = getcontext.ContextAPI(credential=Credential(token))

c.log.conversation(
    body={
        "conversation": Conversation(
            messages=[
                Message(
                    message="You are a helpful assistant!",
                    role=MessageRole.SYSTEM,
                ),
                Message(
                    message="Hello, world!",
                    role=MessageRole.USER,
                ),
                Message(
                    message="Hi, how can I help?",
                    role=MessageRole.ASSISTANT,
                    rating=Rating.POSITIVE,
                ),
            ],
        )
    }
)
```

### Async Example

```python
import asyncio

import getcontext.generated.aio as getcontext
from getcontext.generated.models import Conversation, Message, MessageRole, Rating
from getcontext.token import AsyncCredential
import os

token = os.environ.get("GETCONTEXT_TOKEN")


async def log():
    async with getcontext.ContextAPI(credential=AsyncCredential(token)) as client:
        await client.log.conversation(
            body={
                "conversation": Conversation(
                    messages=[
                        Message(
                            message="You are a helpful assistant!",
                            role=MessageRole.SYSTEM,
                        ),
                        Message(
                            message="Hello, world!",
                            role=MessageRole.USER,
                        ),
                        Message(
                            message="Hi, how can I help?",
                            role=MessageRole.ASSISTANT,
                            rating=Rating.POSITIVE,
                        ),
                    ],
                )
            }
        )


loop = asyncio.get_event_loop()
loop.run_until_complete(log())
loop.close()
```

## Appendix

```yaml
python: true
output-folder: getcontext/generated/
no-namespace-folders: true
credential-default-policy-type: BearerTokenCredentialPolicy
black: true
python3-only: true
add-credential: true
credential-scopes: all
models-mode: msrest
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "context-python",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "context, api, sdk",
    "author": "Alex Gamble",
    "author_email": "alex@context.ai",
    "download_url": "https://files.pythonhosted.org/packages/8c/cb/294fc7b84432d47315ff90a45cec9c9f8ea868ba35dac9646dd05aace528/context_python-0.14.0.tar.gz",
    "platform": null,
    "description": "# Context Python Library\n\n[![PyPI version](https://badge.fury.io/py/context-python.svg)](https://badge.fury.io/py/context-python)\n\nThe Context Python library provides a convenient way to interface with the Context APIs. We include pre-defined classes and operations to interact with API resources.\n\n## Installation\n\n```\npip install --upgrade context-python\n```\n\n## Usage\n\nThe library needs to be configured with your Context API key, which is available in the [Context Settings Dashboard](https://go.getcontext.ai/settings).\n\n### Synchronous Example\n\n```python\nimport getcontext\nfrom getcontext.generated.models import Conversation, Message, MessageRole, Rating\nfrom getcontext.token import Credential\nimport os\n\ntoken = os.environ.get(\"GETCONTEXT_TOKEN\")\n\nc = getcontext.ContextAPI(credential=Credential(token))\n\nc.log.conversation(\n    body={\n        \"conversation\": Conversation(\n            messages=[\n                Message(\n                    message=\"You are a helpful assistant!\",\n                    role=MessageRole.SYSTEM,\n                ),\n                Message(\n                    message=\"Hello, world!\",\n                    role=MessageRole.USER,\n                ),\n                Message(\n                    message=\"Hi, how can I help?\",\n                    role=MessageRole.ASSISTANT,\n                    rating=Rating.POSITIVE,\n                ),\n            ],\n        )\n    }\n)\n```\n\n### Async Example\n\n```python\nimport asyncio\n\nimport getcontext.generated.aio as getcontext\nfrom getcontext.generated.models import Conversation, Message, MessageRole, Rating\nfrom getcontext.token import AsyncCredential\nimport os\n\ntoken = os.environ.get(\"GETCONTEXT_TOKEN\")\n\n\nasync def log():\n    async with getcontext.ContextAPI(credential=AsyncCredential(token)) as client:\n        await client.log.conversation(\n            body={\n                \"conversation\": Conversation(\n                    messages=[\n                        Message(\n                            message=\"You are a helpful assistant!\",\n                            role=MessageRole.SYSTEM,\n                        ),\n                        Message(\n                            message=\"Hello, world!\",\n                            role=MessageRole.USER,\n                        ),\n                        Message(\n                            message=\"Hi, how can I help?\",\n                            role=MessageRole.ASSISTANT,\n                            rating=Rating.POSITIVE,\n                        ),\n                    ],\n                )\n            }\n        )\n\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(log())\nloop.close()\n```\n\n## Appendix\n\n```yaml\npython: true\noutput-folder: getcontext/generated/\nno-namespace-folders: true\ncredential-default-policy-type: BearerTokenCredentialPolicy\nblack: true\npython3-only: true\nadd-credential: true\ncredential-scopes: all\nmodels-mode: msrest\n```\n",
    "bugtrack_url": null,
    "license": "LICENSE.md",
    "summary": "Python SDK for the Context API",
    "version": "0.14.0",
    "project_urls": null,
    "split_keywords": [
        "context",
        " api",
        " sdk"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "26b5b5f9769c043f66eabbcc1fddab8527c1f68fd3c0d80a87370bde8542656e",
                "md5": "5035eb176e4fe4f3bd440ecbf686527e",
                "sha256": "76a0cdda55f20d2ef62ed0b139043fa05b1ea675586740e6077cf2b77e6481b0"
            },
            "downloads": -1,
            "filename": "context_python-0.14.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5035eb176e4fe4f3bd440ecbf686527e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 57370,
            "upload_time": "2024-04-30T12:27:57",
            "upload_time_iso_8601": "2024-04-30T12:27:57.982401Z",
            "url": "https://files.pythonhosted.org/packages/26/b5/b5f9769c043f66eabbcc1fddab8527c1f68fd3c0d80a87370bde8542656e/context_python-0.14.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8ccb294fc7b84432d47315ff90a45cec9c9f8ea868ba35dac9646dd05aace528",
                "md5": "1ed7582da1baa01ac62aab846b52e7f8",
                "sha256": "dcccf7c49b1e44378511dbfeedac8e78bf4cf388f4dc47f12c2acd93cdee9b2e"
            },
            "downloads": -1,
            "filename": "context_python-0.14.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1ed7582da1baa01ac62aab846b52e7f8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 48118,
            "upload_time": "2024-04-30T12:27:59",
            "upload_time_iso_8601": "2024-04-30T12:27:59.387086Z",
            "url": "https://files.pythonhosted.org/packages/8c/cb/294fc7b84432d47315ff90a45cec9c9f8ea868ba35dac9646dd05aace528/context_python-0.14.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-30 12:27:59",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "context-python"
}
        
Elapsed time: 0.24686s