Skip to main content

Check Point AI Security Official Python SDK

Project description

Check Point - AI Security Python SDK

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.0rc2.tar.gz (88.1 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.0rc2-py3-none-any.whl (311.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for haimkastner_ai_security_sdk-1.0.0rc2.tar.gz
Algorithm Hash digest
SHA256 be65986d73fa1fc0c0ebc22119a9a3c87ae546cb1907ae971e2fa4dbfcb235fe
MD5 75abc6930857a58e310eb74343d3eca3
BLAKE2b-256 eec7febb3609111a21472e743957819fa0989329673233aeb227c1420045b2e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for haimkastner_ai_security_sdk-1.0.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 3844540894a96d7e25546f185ca80c282abcca1b817c29bada211633eaee04ca
MD5 a62ab2cc0e9d061a6e0b93f04f9b0cb9
BLAKE2b-256 d0c1d49b177fe6409789f5ea754940c95639d1eb707779f7ea3b5264b1bbb65e

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