Context Python Library
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.
Synchronous Example
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
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
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
Metadata
Release files for context-python 0.18.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| context_python-0.18.0.tar.gz | 42.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| context_python-0.18.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 92.2 kB
Release files / context_python-0.18.0.tar.gz
| Download URL | context_python-0.18.0.tar.gz |
|---|---|
| Size | 42.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
052ecc47e5b0484447827ab35415deaacaa436f68bf1acfb901566f0d4c35633
|
|
BLAKE2b-256 checksum How to use checksums |
44c525e103fcd9a5a6ff865de06040a6cd5d857d7f2b6a11755ca949864ea836
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.11.7 Darwin/23.4.0
|
Release files / context_python-0.18.0-py3-none-any.whl
| Download URL | context_python-0.18.0-py3-none-any.whl |
|---|---|
| Size | 50.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0b2fcd6e7111fdd621cca4d340aa0dd2a3d0d8c33989ad4c9472ceafa03766c
|
|
BLAKE2b-256 checksum How to use checksums |
c213808b24ee09b90bc1b2f6e5877bb1247568e51b9d85b96be266063ff276f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.11.7 Darwin/23.4.0
|
Security for context-python 0.18.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.