Skip to main content

People analytics itsm sdk is used to facilitate integrations and also code reuse

Project description

people-analytics-itsm-sdk

PyPI Latest Release Downloads

Interact with various ServiceNow functionality within your python application, includes the ability to perform create, read, update, and delete (CRUD) operations on existing tables, insert data into, retrieve information from and submit tickets.

Installation

# or PyPI
pip install people-analytics-itsm-sdk

Environment variables

To use people-analytics-itsm-sdk library, you need set four environment variables:

# ---DOTENV EXAMPLE---
ITSM_SERVICENOW_URL=https://service-now.com # base url of you servicenow server
ITSM_SERVICENOW_API_TOKEN= # servicenow auth token
ITSM_SERVICENOW_API_USER= # servicenow user
ITSM_SERVICENOW_API_PASSWORD= # servicenow user password

# you can choose beetwen user and password or api token to authentication

We recommended you to create a .env file in your project root to set environment variables.

Coding in Windows OS

On coding in Windows OS, you need set the environment variables before import people-analytics-itsm-sdk library

import os
# set environment variables before import people-analytics-itsm-sdk library
os.environ["ITSM_SERVICENOW_URL"] = "https://your-service-now-base-path.com"
os.environ["ITSM_SERVICENOW_API_TOKEN"] = "Your api token"
os.environ["ITSM_SERVICENOW_API_USER"] = "your.user.email@domain.com"
os.environ["ITSM_SERVICENOW_API_PASSWORD"] = "your password"

from people_analytics_itsm_sdk.sdk import Records

Example Usage

Get data from servicenow table

To get data from servicenow table, we use Records class.

from people_analytics_itsm_sdk.sdk import Records


# This code get all records in one servicenow table
table_name = "sys_user" # replace this with table name are you need
records = Records(table=table_name)

table_data = records.all() # all() method return all records

Querying

You can apply filters and select columns in the table using Records().query method. For example:

from datetime import datetime, timedelta
from people_analytics_itsm_sdk.sdk import Records


table_name = "incident"
records = Records(table=table_name)

# define date interval to filter
start = datetime(1970, 1, 1)
end = datetime.now() - timedelta(days=20)

# query registers of incident with number started with 'INC0123', created between 1970-01-01 and 20 days old
records.query.field('number').starts_with('INC0123')\
    .AND().field('sys_created_on').between(start, end)\
    .AND().field('sys_updated_on').order_descending()

data = records.all() # return all records of query

Update tables

to create, delete and update records in a servicenow table, you can use Manager class.

from people_analytics_itsm_sdk.sdk import Manager


table_name = "name of table you need update"
manager = Manager(table=table_name)

# create new register in table example
register_to_create = {
    "field1": "value1",
    "field2": "value2",
}

manager.create(data=register_to_create)

# update register in table example
register_update_sys_id = "id of register you need update"
register_data_to_update = {
    "field1": "value4"
}
manager.update(sys_id=register_update_sys_id, data=register_data_to_update)

# delete register in table example
register_delete_sys_id = "id of register you need delete"
manager.delete(sys_id=register_delete_sys_id)

Submit tickets

To submit tickets, you can use ProducerServiceCatalog class.

from people_analytics_itsm_sdk.sdk import ProducerServiceCatalog


survey_catalog_id = "id of your ticket survey in servicenow catalog"
variables = {
    "question1": "value1",
    "question2": "value2"
}

producer_catalog = ProducerServiceCatalog()

result = producer_catalog.store(catalog_id=survey_catalog_id, variables=variables)

Query params

field(field)

Define the field to operate

parameters: field – field (str) to operate

order_descending()

Define a order descending of field

order_ascending()

Define a order ascending of field

starts_with(starts_with)

adds new STARTSWITH condition

parameters: starts_with – field of correspondence starts with a value provided

ends_with(ends_with)

adds new ENDSWITH condition

parameters: ends_with – field of correspondence ends with a value provided

contains(contains)

adds new LIKE condition

parameters: contains – field of correspondence contains the value provided

not_contains(not_contains)

adds new NOTLIKE condition

parameters: not_contains – field of correspondence not contains the value provided

is_empty()

adds new ISEMPTY condition

is_not_empty()

adds new ISNOTEMPTY condition

equals(data)

adds new IN or EQUALS condition depending on whether a list or string had provided

parameters: data – string or list of values

raise: QueryTypeError: if the data provided are of an unexpected kind

not_equals(data)

adds a new NOT IN ou EQUALS condition depending on whether a list or string had provided

parameters: data – string or list of values

raise: QueryTypeError: if the data provided are of an unexpected kind

greater_than(greater_than)

adds a new GREATER THAN condition

parameters: greater_than – object compatible with string or datetime (naive UTC datetime or tz-aware datetime)

raise: QueryTypeError: if greater_than provided are of an unexpected kind

less_than(less_than)

adds new LESS THAN condition

parameters: less_than – object compatible with string or datetime (naive UTC datetime or tz-aware datetime)

raise: QueryTypeError: if less_than provided are of an unexpected kind

between(start, end)

adds a new BETWEEN condition

parameters: start – object compatible with integer or datetime (in the user's time zone SNOW) end – object compatible with integer or datetime (in the user's time zoneSNOW)

raise: QueryTypeError: if the initial or final arguments are of an invalid type

AND()

adds a new AND operator

OR()

adds a new OR operator

NQ()

adds a new NQ operator (new query)

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

people_analytics_itsm_sdk-0.0.15.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

people_analytics_itsm_sdk-0.0.15-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file people_analytics_itsm_sdk-0.0.15.tar.gz.

File metadata

  • Download URL: people_analytics_itsm_sdk-0.0.15.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.14 Linux/4.14.111+

File hashes

Hashes for people_analytics_itsm_sdk-0.0.15.tar.gz
Algorithm Hash digest
SHA256 b3a7828e64b312d39ef53e83b1172cb741f6d89b79092e862951d21a84a82291
MD5 7df0fd576a90e0d1a075cc06a7b2160d
BLAKE2b-256 d5771de5097720da2a73578cfd4b6780eb332f499b4f9ab629a6f881a39f6242

See more details on using hashes here.

File details

Details for the file people_analytics_itsm_sdk-0.0.15-py3-none-any.whl.

File metadata

File hashes

Hashes for people_analytics_itsm_sdk-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 83415220969d303439fde975256ffaa865493a5ca08d77d6804b5cd7f833fe9a
MD5 72266e02097fed976741a4c411269aac
BLAKE2b-256 7db49e9fce192d96e20cb513e635751ffb0f17bfe86ae74c36027c69fafe33e0

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