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:
execution = Stackspot.instance().ai.quick_command.poll_execution(execution_id)

print('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-0.0.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

stackspot-0.0.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stackspot-0.0.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for stackspot-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d3d245c5171b3d39e4244fe9045d030a58d2d5cb6d07579dbadbd999cdc43a47
MD5 e2d8d4194fcea2eca48d1741ba89876b
BLAKE2b-256 81ff9a766301ed831b359d20377b114343b23d5457321f59720979d9051803ce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stackspot-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for stackspot-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 34421a574178493d88c6ef59460a967899b0c89ba0d7ac7b4145f8de073a2b1b
MD5 72c98a96bcf77b54c71d8b5745d23acf
BLAKE2b-256 4d2c4251f306754e75fb3c9071348ae1891f422ffd04e37417b174259042f988

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