Skip to main content

Stackspot API bindings for Python

Project description

Stackspot

NPM Version

Stackspot API bindings for Python.



Content




Installation

To install, simply add the package using pip:

pip install stackspot



Usage

You can start using the global instance:

from stackspot import Stackspot

# By default, the global instance will configure itself using the environment variables:
# - STACKSPOT_CLIENT_ID
# - STACKSPOT_CLIENT_SECRET
# - STACKSPOT_REALM

# Creating a new 'Knowledge Source' for example:
Stackspot.instance().ai.ks.create_ks('new-ks-test-api-2', 'New KS test', 'This is a test KS', 'CUSTOM')

⚙ Configuration

You can configure the global instance:

from stackspot import Stackspot

# Using the 'config(opts)' method, to update the all the settings at once:
Stackspot.instance().config({
	'client_id': '...',
	'client_secret': '...',
	'realm': '...',
})



# Or update them individually:
Stackspot.instance() \
	.set_client_id('...') \
	.set_client_secret('...')

If you want to create your own Stackspot instance, you can either pass the settings on the constructor, use the 'config' method, or configure individual properties as well:

from stackspot import Stackspot

# Creating a new stackspot instance (instead of using the 'global' one):
my_instance = Stackspot({
	'client_id': '...',
	'client_secret': '...',
	'realm': '...'
})


# If you want, it's possible to call the 'config(opts)' method of this instance as well to update the settings:
my_instance.config({ ... })


# Or configure properties individually:
my_instance.set_client_id('...')

🌐 Using behind proxy

Internally it uses the requests module to make requests, so you can just provide the standard HTTP_PROXY/HTTPS_PROXY/NO_PROXY environment variables.

See more: Proxies with 'requests' module.




Methods

Here are all the available methods of this package:


✨ AI

All the AI related functions are bellow Stackspot.instance().ai namespace.


AI - KS - Create a new Knowledge Source

To create a new Knowledge Source, just run:

from stackspot import Stackspot

Stackspot.instance().ai.ks.create_ks('my-new-ks', 'My new KS', 'A test KS', 'CUSTOM')

For more info about the KS creation, check out the official documentation: https://ai.stackspot.com/docs/knowledge-source/create-knowledge-source


AI - KS - Upload new file to a Knowledge Source

You can add or update existing objects inside a Knowledge Source:

from stackspot import Stackspot

# This creates/updates a KS object named 'test.txt' containing 'Hello World' text:
Stackspot.instance().ai.ks.upload_ks_object('my-ks-slug', 'test.txt', 'Hello World')

AI - KS - Remove files from a Knowledge Source

To batch remove files from a Knowledge Source:

from stackspot import Stackspot

# This removes ALL objects from the KS:
Stackspot.instance().ai.ks.batch_remove_ks_objects('my-ks-slug', 'ALL')
from stackspot import Stackspot

# This removes only the STANDALONE objects from the KS:
Stackspot.instance().ai.ks.batch_remove_ks_objects('my-ks-slug', 'STANDALONE')
from stackspot import Stackspot

# This removes only the UPLOADED objects from the KS:
Stackspot.instance().ai.ks.batch_remove_ks_objects('my-ks-slug', 'UPLOADED')

AI - Quick Command - Create a new execution

To manually create a new Quick Command execution:

from stackspot import Stackspot

execution_id = Stackspot.instance().ai.quick_command.create_execution('my-quick-command-slug', 'Input for this execution')
# Return example: "06J85YZZ5HVO1XXCKKR4TJ16N2"

AI - Quick Command - Get execution

After creating a new Quick Command execution, you may want to check it to see if it has completed successfully, and get its result:

from stackspot import Stackspot

execution = Stackspot.instance().ai.quick_command.get_execution('06J85YZZ5HVO1XXCKKR4TJ16N2')

print('status: ' + execution['progress']['status'])

Obs.: Note that, at the time this call have been made, the execution may not yet be done, so you have to write some polling logic, or use the 'poll_execution' method.


AI - Quick Command - Poll execution until it's done

It can be cumbersome to write the logic to poll a Quick Command execution after its creation to check if it's done. This library gets you covered on that:

from stackspot import Stackspot

# Just create a new execution:
execution_id = Stackspot.instance().ai.quick_command.create_execution('my-quick-command-slug', 'Input for this execution')

# And call the poll method:
# This will check the execution status until it's done and then return the execution object (the 'opts' argument is optional):
execution = Stackspot.instance().ai.quick_command.poll_execution(execution_id, { 'delay': 0.5, 'on_callback_response': lambda e: print('status: ' + e['progress']['status']) })

print('final status: ' + execution['progress']['status']) # 'COMPLETED'
print('result: ' + execution['result']) # The Quick Command result.


🗝️ Auth

The library methods already handles the authentication process, but you can access the auth methods by yourself using the Stackspot.instance().auth namespace:


Auth - Get the access token

This will get the cached token, or fetch a new one if they aren't valid anymore:

from stackspot import Stackspot

Stackspot.instance().auth.get_access_token()

Obs.: To configure the authentication properties like client_id, client_secret, and realm, head back to the Usage section.




License

MIT

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

stackspot-1.0.1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

stackspot-1.0.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file stackspot-1.0.1.tar.gz.

File metadata

  • Download URL: stackspot-1.0.1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for stackspot-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9250da274fb60c3869070a23776c36dbc8f90dfaf173ea3befaf392d072b7a0b
MD5 4e9117c23d55a2e7caa68a52295a8f44
BLAKE2b-256 ce698a23350e2083a9da668b27d898ca2dc49eedea14f6f89c99f856336517a8

See more details on using hashes here.

File details

Details for the file stackspot-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: stackspot-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for stackspot-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 839413e9c8d1b12cf72917fa1e8ac778530ce80d9c44e83f6605faa0246a06a1
MD5 153a2020b65250c9dfc79f79440e398e
BLAKE2b-256 7f9b7927e484988aa714e89e6f936ca3980d7adbf4a04b9164b9cd7525d437de

See more details on using hashes here.

Supported by

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