Quickstart

Using imperva-sdk is as easy as using the MX UI.

Installation

You can install imperva-sdk on pretty much any machine with Python version 2.6+ (tested with 2.6, 2.7, 3.3 and 3.6 to 3.11). If you use Python 3.10 or above, please download Imperva SDK version 0.2.2 or above. The only requirement is the Python requests library.

  1. Download

Download the latest imperva-sdk package from the Downloads section.

  1. Unpack and Install the package

$ tar xf imperva-sdk-*.tar.gz
$ cd imperva-sdk-*
$ python setup.py install

You can also install the package with pip (or any other Python package manager).

  1. Start using imperva-sdk

import imperva_sdk
mx = imperva_sdk.MxConnection("1.2.3.4")
sites = mx.get_all_sites()

Downloads

imperva-sdk downloads:

Version

Development Status

Download

0.2.2

Latest (September 2023)

imperva-sdk-latest-wip.tar.gz

0.2.1

Latest stable (November 2020)

imperva-sdk-latest.tar.gz

0.2.0

Generally Available (July 2019)

imperva-sdk-0.2.0.tar.gz

Using imperva-sdk

This is just a small sample of what you can do with imperva-sdk. Make sure you check out the API Reference for more information.

import imperva_sdk

# Create a connection to the MX
mx = imperva_sdk.MxConnection(Host="10.0.0.1", Port=8083, Username="admin", Password="password")

# Display MX version
mx.Version
u'12.0.0.41'

# Create Site
site = mx.create_site("Gioras Site")

# Create Server Group
server_group = site.create_server_group("Gioras Server Group")

# Create Web Service
web_service = server_group.create_web_service("Gioras Web Service")

# Change Server Group Operation Mode from Simulation to Active
server_group.OperationMode
'simulation'
server_group.OperationMode = 'active'

# Create KRP Rule
krp_rule = web_service.create_krp_rule(Alias="alias name", GatewayGroup="gg name", GatewayPorts=[80], OutboundRules=[{'priority': 1, 'internalIpHost': 'www.imperva.com', 'serverPort': 80}])

# Display Site in JSON (Python dict) format. Check out the export_to_json and import_from_json functions as well.
dict(site)
{'server_groups': [{'web_services': [{'krp_rules': [{'OutboundRules': [{u'internalIpHost': u'www.imperva.com', u'encrypt': False, 'clientAuthenticationRules': None, 'urlPrefix': None, 'priority': 1, u'serverPort': 80, 'externalHost': None, u'validateServerCertificate': False}], 'GatewayPorts': [80], 'GatewayGroup': u'gg name', 'Alias': u'alias name', 'ClientAuthenticationAuthorities': None, 'ServerCertificate': None}], 'SslPorts': [443], 'Name': u'Gioras Web Service', 'Ports': [80]}], 'Name': u'Gioras Server Group', 'OperationMode': u'active'}], 'Name': 'Gioras Site'}

# Delete Site
mx.delete_site(site.Name)