Skip to main content

Contextal Python Package

This package provides a simple way to interact with Contextal Platform via API. It includes a Python library and command-line tools to perform essential tasks such as file uploads, scenario management, and retrieval of analysis results.

Installation

pip install contextal

Usage

Library example

Here's an example of how to use the library to upload a file and obtain the results from scenarios (if any):

from contextal import Config, Platform
from time import sleep

config = Config()
config.url = "http://contextal.my_company.lan"
#config.token = "my_token"
platform = Platform(config)
file = open("my_sample", "rb")
work = platform.submit_work(file)
sleep(1)
actions = platform.get_actions(work["work_id"])
print(actions)

Command line examples

# create default profile
ctx config create local_cloud http://contextal.my_company.lan --set-default
# create additional profile
ctx config create public_cloud https://contextal.my_company.com --token glpat-my-token
# upload file
ctx work submit my_sample --profile public_cloud
#upload file using default profile
ctx work submit my_sample
# check work results
ctx work graph MY_WORK_ID --pretty
# check scenarios results (i.e. the recommended actions) for a work
ctx work actions MY_WORK_ID --pretty

Add a new scenario:

ctx scenario add "-"<<EOF
{
    "action": "BLOCK",
    "creator": "me@my_company.com",
    "context": null,
    "description": "Block all mails containing windows link files",
    "local_query": "object_type=\"LNK\" && @has_root(object_type == \"Email\")",
    "max_ver": null,
    "min_ver": 1,
    "name": "MAIL_WITH_LNK"
}
EOF
# call the reload option to make Contextal Platform start using any new scenarios
ctx scenario reload

Scenarios can be downloaded and used as a backup or template for new ones:

ctx scenario details SCENARIO_ID > scenario1.backup
# modify scenario using jq command
cat scenario1.backup | jq '.name="MAIL_WITH_PE"|.local_query="object_type=\"PE\" && @has_root(object_type == \"Email\")"' > scenario2
# add scenario2
ctx scenario add scenario2
# call the reload option to make Contextal Platform start using any new scenarios
ctx scenario reload

License

This package is distributed under the MIT License. See the LICENSE.txt file for more details.

Release files for contextal 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for contextal 1.0.1
File Size Uploaded
contextal-1.0.1.tar.gz 10.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for contextal 1.0.1
File Interpreter ABI Platform
contextal-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 26.0 kB

Release files / contextal-1.0.1.tar.gz

Download URL contextal-1.0.1.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5dd54fe276940a3cec25e2bdb4e9f8f52172f938670004afb0a22845bd4ef7ef
BLAKE2b-256 checksum
How to use checksums
4bc9c1e649cc8493517326576b348a4824e699df1a62acbb9d0c24e3b8995f97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release files / contextal-1.0.1-py3-none-any.whl

Download URL contextal-1.0.1-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66698b99439282982f0bbac0441c28cced5147d7094fc00c6a9d5c7fe0275503
BLAKE2b-256 checksum
How to use checksums
0f6ecfe7b76c1a976675acc8a07c030499bdd35f7434a4891f9b9383467787b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page