Package: zanshinsdk
Zanshin Python SDKThis Python package contains an SDK to interact with theAPI of the
Zanshin SaaS servicefromTenchi Security.This SDK is used to implement a command-line utility, which is available
onGithuband onPyPI.Setting up CredentialsThere are three ways that the SDK handles credentials. The order of
evaluation is:1st Client Parameters2nd Environment Variables3rd Config FileClient ParametersWhen calling theClientclass, you can pass the values API Key, API
URL, Proxy URL and User Agent you want to use as below:fromzanshinsdkimportClientclient=Client(api_key="my_zanshin_api_key")print(client.get_me())⚠️ These values will overwrite anything you set as Environment
Variables or in the Config File.Environment VariablesYou can use the following Environment Variables to configure Zanshin
SDK:ZANSHIN_API_KEY: Will setup your Zanshin credentialsZANSHIN_API_URL: Will define the API URL. Default ishttps://api.zanshin.tenchisecurity.comZANSHIN_USER_AGENT: If you want to overwrite the User Agent when
calling Zanshin APIHTTP_PROXY | HTTPS_PROXY: Zanshin SDK uses HTTPX under the hood,
checkout theEnvironment
Variablessection of their documentation for more use casesUsageexportZANSHIN_API_KEY="eyJhbGciOiJIU..."⚠️ These Environment Variables will overwrite anything you set on the
Config File.Config FileSecond is by using a configuration file in the format created by the
PythonRawConfigParserclass.The file is located at~/.tenchi/config, where~is thecurrent
user’s home
directory.Each section is treated as a configuration profile, and the SDK will
look for a section calleddefaultif another is not explicitly
selected.These are the supported options:api_key(required) which contains the Zanshin API key obtained at
theZanshin 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=abcdefghijklmnopqrstuvxyzThe SDKThe 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 wonderfulhttpxlibrary.Currently it focuses on returning the parsed JSON values instead of
converting them into native classes for higher level abstractions.Thezanshinsdk.Clientclass 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:fromzanshinsdkimportClientfromjsonimportdumpsclient=Client()# loads API key from the "default" profile in ~/.tenchi/configme=client.get_me()# calls /me API endpointprint(dumps(me,indent=4))For more examples, checkout thedocs.All operations callraise_for_statuson the httpxResponse
objectinternally, so
any 4xx or 5xx will raiseexceptions.InstallingTo install the SDK, you can usepip. You have two options to install
ZanshinSDK:EssentialsUsingpip install zanshinsdkwill install the SDK with all features
exception ability to perform onboarding of new Scan Targets. For this,
you’ll need to install boto3.With Boto3Withpip install zanshinsdk[with_boto3]you’ll automatically installboto3along with ZanshinSDK. This will enable you to perform Onboard of new
Scan Targets via SDK.TestingTo run all tests callmake teston the project root directory. Make
sure there’s a[default]profile configured, else some tests will
fail. Also, be sure to installboto3andmoto[all]or some
integration tests will fail.SupportIf 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 theZanshin Portal.