Skip to main content

Check Point AI Security Official Python SDK

Project description

Check Point - AI Security Python SDK

Draft – This is a pre-release version of the SDK published for early testing. APIs and behavior may change before the official release.

License Latest Release PyPI version

Build SDK Package Publish package to PyPI

This is the AI Security SDK for Python ecosystem.

The SDK is based on the public AI Security OpenAPI specifications.

With the SDK, you do not have to manage log in, send keep alive requests, or worry about session expiration.

The AI Security SDK supports simultaneous instances with different tenants.

SDK installation

To start using this SDK, add the SDK package to your project

Via PIP (PyPi registry)

pip install chkp-ai-security-sdk

Getting started

First, import the AISecurity object from the package.

from chkp_ai_security_sdk import AISecurity

Then, create a new instance of AISecurity, which provides CloudInfra API credentials and a gateway to connect to.

Obtaining API credentials

  1. Go to the Infinity Portal API Keys page.
  2. Click New > New Account API Key.
  3. In the Service dropdown select GenAI Protect and create the key.
  4. Copy the Client ID, Secret Key, and Authentication URL (gateway).

For more information, see Infinity Portal Administration Guide.

Available gateways

Region Gateway URL
Europe https://cloudinfra-gw.portal.checkpoint.com
United States https://cloudinfra-gw-us.portal.checkpoint.com

Once the Client ID, Secret Key, and Authentication URL are obtained, AI Security SDK can be used.

All API operations can be explored with the AISecurity instance, notice to the documentation on each API operation, what and where are the arguments it requires.

All APIs can be also explored in SwaggerHub

A complete example:

from chkp_ai_security_sdk import AISecurity, InfinityPortalAuth

# Create a new instance of AISecurity (we do support multiple instances in parallel)
ai = AISecurity()

# Connect to AI Security service using CloudInfra API credentials
ai.connect(infinity_portal_auth=InfinityPortalAuth(
        client_id="place here your CI client-id",   # The "Client ID"
        access_key="place here your CI access-key", # The "Secret Key"
        gateway="https://cloudinfra-gw-us.portal.checkpoint.com" # The "Authentication URL" (without /auth/external)
        ))

# Query the API operations
rulebase = ai.chats_policy_api.get_chats_rulebase_external_v1_chats_rulebase_get()
print(rulebase)

# Once finish, disconnect to stop all background session management.
ai.disconnect()

Async support

The SDK also provides an async variant for use in async Python applications:

import asyncio
from chkp_ai_security_sdk import AsyncAISecurity, InfinityPortalAuth

async def main():
    ai = AsyncAISecurity()
    await ai.connect(infinity_portal_auth=InfinityPortalAuth(
        client_id="your-client-id",
        access_key="your-secret-key",
        gateway="https://cloudinfra-gw-us.portal.checkpoint.com",
    ))

    # API calls are awaitable and run without blocking the event loop
    rulebase = await ai.chats_policy_api.get_chats_rulebase_external_v1_chats_rulebase_get()
    print(rulebase)

    await ai.disconnect()

asyncio.run(main())

Troubleshooting and logging

The full version and build info of the SDK is available by AISecurity.info() see example:

from chkp_ai_security_sdk import AISecurity, WorkforceAISDKInfo

sdk_info: WorkforceAISDKInfo = AISecurity.info()
print(sdk_info) # sdk_build:"9728283", sdk_version:"1.0.0", spec:"checkpoint-ai-security", spec_version:"1.0.0", released_on:"2024-01-01T00:00:00"

AI Security SDK uses the official python logger package for logging.

There are 3 loggers, for general info, errors and to inspect network.

As default they will be disabled, in order to enable logging, set to the AI_SECURITY_SDK_LOGGER environment variable the following string before loading the SDK:

AI_SECURITY_SDK_LOGGER="*"

And for a specific/s logger set the logger name followed by a comma as following:

AI_SECURITY_SDK_LOGGER="info,error,network"

or activate logger programmatically using SDK methods:

from chkp_ai_security_sdk import activate_all_loggers, activate_info_logger, activate_error_logger, activate_network_logger
...
activate_all_loggers()    # Will activate all loggers
activate_info_logger()    # Will activate the info logger only
activate_error_logger()   # Will activate the error logger only
activate_network_logger() # Will activate the network logger only

All Check Point AI Security API tools

Tool Package
Python SDK chkp-ai-security-sdk
JS/TS SDK @chkp/ai-security-sdk
OpenAPI Spec SwaggerHub

Report Bug

In case of an issue or a bug found in the SDK, please open an issue.

Contributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haimkastner_ai_security_sdk-1.0.0rc3.tar.gz (88.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

haimkastner_ai_security_sdk-1.0.0rc3-py3-none-any.whl (312.0 kB view details)

Uploaded Python 3

File details

Details for the file haimkastner_ai_security_sdk-1.0.0rc3.tar.gz.

File metadata

File hashes

Hashes for haimkastner_ai_security_sdk-1.0.0rc3.tar.gz
Algorithm Hash digest
SHA256 fd5c1404c9875c431b34d28137e2c9bc9f495a11a21e8ab8e3e099de157996a1
MD5 5b792fa8f31dbcbcb59b79f69cadfe43
BLAKE2b-256 ca352e8e0758b8cb698cabf6763d0fec244afedcabd42d44ac99545ed3a9535e

See more details on using hashes here.

File details

Details for the file haimkastner_ai_security_sdk-1.0.0rc3-py3-none-any.whl.

File metadata

File hashes

Hashes for haimkastner_ai_security_sdk-1.0.0rc3-py3-none-any.whl
Algorithm Hash digest
SHA256 897acd6d9172946b26520d83950bb6daafadabc7c06ba90cdcfc73c867e457e8
MD5 2d20cb43c452c8f48cfee8ba8156d643
BLAKE2b-256 4cf0325970889673a9714e2ad87542a2f7ca8c298b77859b80c4163556aa2c97

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page