Skip to main content

 Coverage badge PyPI version shields.io PyPI pyversions

Zanshin Python SDK

This Python package contains an SDK to interact with the API of the Zanshin SaaS service from Tenchi Security.

This SDK is used to implement a command-line utility, which is available on Github and on PyPI.

Setting up Credentials

There are three ways that the SDK handles credentials. The order of evaluation is:

Client Parameters

When calling the Client class, you can pass the values API Key, API URL, Proxy URL and User Agent you want to use as below:

from zanshinsdk import Client

client = Client(api_key="my_zanshin_api_key")

print(client.get_me())

:warning: These values will overwrite anything you set as Environment Variables or in the Config File.

Environment Variables

You can use the following Environment Variables to configure Zanshin SDK:

  • ZANSHIN_API_KEY: Will setup your Zanshin credentials
  • ZANSHIN_API_URL: Will define the API URL. Default is https://api.zanshin.tenchisecurity.com
  • ZANSHIN_USER_AGENT: If you want to overwrite the User Agent when calling Zanshin API
  • HTTP_PROXY | HTTPS_PROXY: Zanshin SDK uses HTTPX under the hood, checkout the Environment Variables section of their documentation for more use cases

Usage

export ZANSHIN_API_KEY="eyJhbGciOiJIU..."

:warning: These Environment Variables will overwrite anything you set on the Config File.

Config File

Second is by using a configuration file in the format created by the Python RawConfigParser class.

The file is located at ~/.tenchi/config, where ~ is the current user's home directory.

Each section is treated as a configuration profile, and the SDK will look for a section called default if another is not explicitly selected.

These are the supported options:

  • api_key (required) which contains the Zanshin API key obtained at the Zanshin web portal.
  • user_agent (optional) allows you to override the default user-agent header used by the SDK when making API requests.
  • api_url (optional) directs the SDK to use a different API endpoint than the default (https://api.zanshin.tenchisecurity.com).

This is what a minimal configuration file looks like:

[default]
api_key = abcdefghijklmnopqrstuvxyz

The SDK

The SDK uses Python 3 type hints extensively. It attempts to abstract API artifacts such as pagination by using Python generators, thus making the service easier to interact with.

The network connections are done using the wonderful httpx library.

Currently it focuses on returning the parsed JSON values instead of converting them into native classes for higher level abstractions.

The zanshinsdk.Client class is the main entry point of the SDK. Here is a quick example that shows information about the owner of the API key in use:

from zanshinsdk import Client
from json import dumps

client = Client()   # loads API key from the "default" profile in ~/.tenchi/config
me = client.get_me()    # calls /me API endpoint
print(dumps(me, indent=4))

For more examples, checkout the docs.

All operations call raise_for_status on the httpx Response object internally, so any 4xx or 5xx will raise exceptions.

Installing

To install the SDK, you can use pip. You have two options to install ZanshinSDK:

  • Essentials

Using pip install zanshinsdk will install the SDK with all features exception ability to perform onboarding of new Scan Targets. For this, you'll need to install boto3.

  • With Boto3

With pip install zanshinsdk[with_boto3] you'll automatically install boto3 along with ZanshinSDK. This will enable you to perform Onboard of new Scan Targets via SDK.

Testing

To run all tests call make test on the project root directory. Make sure there's a [default] profile configured, else some tests will fail. Also, be sure to install boto3 and moto[all] or some integration tests will fail.

Support

If you are a Zanshin customer and have any questions regarding the use of the service, its API or this SDK package, please get in touch via e-mail at support {at} tenchisecurity {dot} com or via the support widget on the Zanshin Portal.

Release files for zanshinsdk 2.3.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 zanshinsdk 2.3.1
File Size Uploaded
zanshinsdk-2.3.1.tar.gz 43.0 kB Details

Built distribution (wheel)

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

Total release size:89.6 kB

Release files / zanshinsdk-2.3.1.tar.gz

Download URL zanshinsdk-2.3.1.tar.gz
Size 43.0 kB
Tags Source
SHA-256 checksum
How to use checksums
56b57d4f1e7316fe453315e49cd9deb06777ad7f2706eb32e117c97b6114a87d
BLAKE2b-256 checksum
How to use checksums
7560de9c170ef0dd3b13b72c5c86837bd2e3186b357e6502bd10fbfe5adf24ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.20 Linux/6.17.0-1010-azure

Release files / zanshinsdk-2.3.1-py3-none-any.whl

Download URL zanshinsdk-2.3.1-py3-none-any.whl
Size 46.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90c98c2f106f5f3feb0e598f1f073096892e6c455a8790e211c2cc3190c774da
BLAKE2b-256 checksum
How to use checksums
5f6cb102a61455140d21cf7a0bcf3d5249d1002688c6c9ba83646c92b7e2466b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.20 Linux/6.17.0-1010-azure

Release history Release notifications | RSS feed

This release

2.3.1 This release

2 release files

2.3

2 release files

2.2

2 release files

2.1.9

2 release files

2.1.8

2 release files

2.1.7

2 release files

2.1.6

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.6.4

2 release files

1.6.3

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6

2 release files

1.5.2

1 release file

1.5.1

1 release file

1.5.0

1 release file

1.4.0

1 release file

1.3.6

1 release file

1.3.5

1 release file

1.3.4

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.8

1 release file

1.2.7

1 release file

1.2.5

1 release file

1.2.4

1 release file

1.2.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.1

1 release file

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