context-python


Namecontext-python JSON
Version 0.18.0 PyPI version JSON
download
home_pageNone
SummaryPython SDK for the Context API
upload_time2024-07-01 14:44:26
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/44/c5/25e103fcd9a5a6ff865de06040a6cd5d857d7f2b6a11755ca949864ea836/context_python-0.18.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.18.0",
    "project_urls": null,
    "split_keywords": [
        "context",
        " api",
        " sdk"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c213808b24ee09b90bc1b2f6e5877bb1247568e51b9d85b96be266063ff276f8",
                "md5": "1bdea939ac4d739e01fc5dae0a6724a8",
                "sha256": "c0b2fcd6e7111fdd621cca4d340aa0dd2a3d0d8c33989ad4c9472ceafa03766c"
            },
            "downloads": -1,
            "filename": "context_python-0.18.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1bdea939ac4d739e01fc5dae0a6724a8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 50127,
            "upload_time": "2024-07-01T14:44:24",
            "upload_time_iso_8601": "2024-07-01T14:44:24.676950Z",
            "url": "https://files.pythonhosted.org/packages/c2/13/808b24ee09b90bc1b2f6e5877bb1247568e51b9d85b96be266063ff276f8/context_python-0.18.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "44c525e103fcd9a5a6ff865de06040a6cd5d857d7f2b6a11755ca949864ea836",
                "md5": "924399279e7ec50853553f09de7dec84",
                "sha256": "052ecc47e5b0484447827ab35415deaacaa436f68bf1acfb901566f0d4c35633"
            },
            "downloads": -1,
            "filename": "context_python-0.18.0.tar.gz",
            "has_sig": false,
            "md5_digest": "924399279e7ec50853553f09de7dec84",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 42049,
            "upload_time": "2024-07-01T14:44:26",
            "upload_time_iso_8601": "2024-07-01T14:44:26.569079Z",
            "url": "https://files.pythonhosted.org/packages/44/c5/25e103fcd9a5a6ff865de06040a6cd5d857d7f2b6a11755ca949864ea836/context_python-0.18.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-01 14:44:26",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "context-python"
}
        
Elapsed time: 0.31682s