Cortex Xpanse Python SDK Readthedocs Io en Latest
Cortex Xpanse Python SDK Readthedocs Io en Latest
Release 2.1.0
1 Subpackages 1
1.1 Cortex Xpanse APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Subpackages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1.1 Cortex Xpanse Asset Management API . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1.2 Cortex Xpanse Attack Surface Rules API . . . . . . . . . . . . . . . . . . . . . . . 6
1.1.1.3 Cortex Xpanse Incident Management API . . . . . . . . . . . . . . . . . . . . . . 8
1.1.1.4 Cortex Xpanse Tags API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2 Submodules 15
3 xpanse.client module 17
4 xpanse.const module 21
5 xpanse.endpoint module 25
6 xpanse.error module 27
7 xpanse.iterator module 29
8 xpanse.response module 31
9 xpanse.types module 33
10 xpanse.utils module 35
Index 43
i
ii
CHAPTER
ONE
SUBPACKAGES
1.1.1 Subpackages
xpanse.api.asset_management.v1.assets module
class AssetsEndpoint(session)
Bases: xpanse.api.asset_management.assets_management_base.
AssetsManagementBaseEndpoint
Part of the Public API for handling Assets. See: https://docs-cortex.paloaltonetworks.com/r/
Cortex-XPANSE/Cortex-Xpanse-API-Reference/Get-All-Assets See: https://docs-cortex.paloaltonetworks.
com/r/Cortex-XPANSE/Cortex-Xpanse-API-Reference/Get-Asset
GET_ENDPOINT = 'public_api/v1/assets/get_asset_internet_exposure/'
LIST_DATA_KEY = 'assets_internet_exposure'
LIST_ENDPOINT = 'public_api/v1/assets/get_assets_internet_exposure/'
count(asset_types: Optional[Set[xpanse.const.AssetType]] = None, request_data:
Optional[xpanse.types.RequestData] = None, **kwargs: Any) →
xpanse.response.XpanseResponse
This endpoint will return a count of Assets.
Parameters
• asset_types (Set[AssetType], Optional) – An optional set of asset types
that can be used to filter your request.
• request_data (RequestData, Optional) – Any supplemental request_data to
be included with your request. This is needed to implement any additional filters, offsets,
limits, or sort ordering.
• **kwargs – Any extraneous parameters you would like to include when executing your
request with the Requests.request module. Note: By default, all payload data is sent under
the “json” keyword for your request.
Returns An object containing the raw requests.Response and parsed data results. The raw re-
sponse can be accessed with <xpanse_reponse>.response attribute. The parsed results can
be accessed with the <xpanse_response>.data attribute.
Return type XpanseResponse
1
Xpanse, Release 2.1.0
Examples
Examples
2 Chapter 1. Subpackages
Xpanse, Release 2.1.0
Examples
xpanse.api.asset_management.v1.owned_ip_ranges module
class OwnedIpRangesEndpoint(session)
Bases: xpanse.api.asset_management.assets_management_base.
AssetsManagementBaseEndpoint
Part of the Public API for handling Owned IP Ranges. See: https://docs-cortex.paloaltonetworks.
com/r/Cortex-XPANSE/Cortex-Xpanse-API-Reference/Get-All-External-IP-Address-Ranges
See: https://docs-cortex.paloaltonetworks.com/r/Cortex-XPANSE/Cortex-Xpanse-API-Reference/
Get-External-IP-Address-Range
GET_ENDPOINT = 'public_api/v1/assets/get_external_ip_address_range/'
LIST_DATA_KEY = 'external_ip_address_ranges'
LIST_ENDPOINT = 'public_api/v1/assets/get_external_ip_address_ranges/'
count(request_data: Optional[xpanse.types.RequestData] = None, **kwargs: Any) →
xpanse.response.XpanseResponse
This endpoint will return a count of Owned IP Ranges.
Parameters
• request_data (RequestData, Optional) – Any supplemental request_data to
be included with your request. This is needed to implement any additional filters, offsets,
limits, or sort ordering.
• **kwargs – Any extraneous parameters you would like to include when executing your
request with the Requests.request module. Note: By default, all payload data is sent under
the “json” keyword for your request.
Returns An object containing the raw requests.Response and parsed data results. The raw re-
sponse can be accessed with <xpanse_reponse>.response attribute. The parsed results can
be accessed with the <xpanse_response>.data attribute.
Return type XpanseResponse
Examples
Examples
Examples
xpanse.api.asset_management.v1.services module
class ServicesEndpoint(session)
Bases: xpanse.api.asset_management.assets_management_base.
AssetsManagementBaseEndpoint
Part of the Public API for handling Services. See: https://docs-cortex.paloaltonetworks.com/r/Cortex-XPANSE/
Cortex-Xpanse-API-Reference/Get-All-External-Services See: https://docs-cortex.paloaltonetworks.com/r/
Cortex-XPANSE/Cortex-Xpanse-API-Reference/Get-External-Service
GET_ENDPOINT = 'public_api/v1/assets/get_external_service/'
4 Chapter 1. Subpackages
Xpanse, Release 2.1.0
LIST_DATA_KEY = 'external_services'
LIST_ENDPOINT = 'public_api/v1/assets/get_external_services/'
count(request_data: Optional[xpanse.types.RequestData] = None, **kwargs: Any) →
xpanse.response.XpanseResponse
This endpoint will return a count of Services.
Parameters
• request_data (RequestData, Optional) – Any supplemental request_data to
be included with your request. This is needed to implement any additional filters, offsets,
limits, or sort ordering.
• **kwargs – Any extraneous parameters you would like to include when executing your
request with the Requests.request module. Note: By default, all payload data is sent under
the “json” keyword for your request.
Returns An object containing the raw requests.Response and parsed data results. The raw re-
sponse can be accessed with <xpanse_reponse>.response attribute. The parsed results can
be accessed with the <xpanse_response>.data attribute.
Return type XpanseResponse
Examples
Examples
Examples
xpanse.api.attack_surface_rules.v1.attack_surface_rules module
class AttackSurfaceRulesEndpoint(session)
Bases: xpanse.endpoint.XpanseEndpoint
Part of the Public API for handling Attack Surface Rules.
DATA_KEY = 'attack_surface_rules'
ENDPOINT = 'public_api/v1/get_attack_surface_rules/'
count(request_data: Optional[xpanse.types.RequestData] = None, **kwargs: Any) →
xpanse.response.XpanseResponse
This endpoint will return a count of Attack Surface Rules.
Parameters
• request_data (RequestData, Optional) – Any supplemental request_data to
be included with your request. This is needed to implement any additional filters, offsets,
limits, or sort ordering.
• **kwargs – Any extraneous parameters you would like to include when executing your
request with the Requests.request module. Note: By default, all payload data is sent under
the “json” keyword for your request.
6 Chapter 1. Subpackages
Xpanse, Release 2.1.0
Returns An object containing the raw requests.Response and parsed data results. The raw re-
sponse can be accessed with <xpanse_reponse>.response attribute. The parsed results can
be accessed with the <xpanse_response>.data attribute.
Return type XpanseResponse
Examples
Examples
Returns An iterator containing all of the Attack Surface Rules results. Results can be iterated
or called by page using <iterator>.next().
Return type XpanseResultIterator
Examples
xpanse.api.incident_management.v1.incidents module
class IncidentsEndpoint(session)
Bases: xpanse.endpoint.XpanseEndpoint
Part of the Public API for handling Incidents. See: https://docs-cortex.paloaltonetworks.com/
r/Cortex-XPANSE/Cortex-Xpanse-API-Reference/Get-Incidents See: https://docs-cortex.paloaltonetworks.
com/r/Cortex-XPANSE/Cortex-Xpanse-API-Reference/Update-an-Incident
DATA_KEY = 'incidents'
LIST_ENDPOINT = 'public_api/v1/incidents/get_incidents/'
UPDATE_ENDPOINT = 'public_api/v1/incidents/update_incident/'
count(request_data: Optional[xpanse.types.RequestData] = None, **kwargs: Any) →
xpanse.response.XpanseResponse
This endpoint will return a count of Incidents.
Parameters
• request_data (RequestData, Optional) – Any supplemental request_data to
be included with your request. This is needed to implement any additional filters, offsets,
limits, or sort ordering.
• **kwargs – Any extraneous parameters you would like to include when executing your
request with the Requests.request module. Note: By default, all payload data is sent under
the “json” keyword for your request.
Returns An object containing the raw requests.Response and parsed data results. The raw re-
sponse can be accessed with <xpanse_reponse>.response attribute. The parsed results can
be accessed with the <xpanse_response>.data attribute.
Return type XpanseResponse
8 Chapter 1. Subpackages
Xpanse, Release 2.1.0
Examples
Examples
Examples
Examples
xpanse.api.incident_management.v2.alerts module
class AlertsEndpoint(session)
Bases: xpanse.endpoint.XpanseEndpoint
Part of the Public API for handling Alerts Multi-Events v2. See: https://docs-cortex.paloaltonetworks.com/r/
Cortex-XPANSE/Cortex-Xpanse-API-Reference/Get-Alerts-Multi-Events
DATA_KEY = 'alerts'
ENDPOINT = 'public_api/v2/alerts/get_alerts_multi_events/'
count(request_data: Optional[xpanse.types.RequestData] = None, **kwargs: Any) →
xpanse.response.XpanseResponse
This endpoint will return a count of Alerts.
Parameters
• request_data (RequestData, Optional) – Any supplemental request_data to
be included with your request. This is needed to implement any additional filters, offsets,
limits, or sort ordering.
• **kwargs – Any extraneous parameters you would like to include when executing your
request with the Requests.request module. Note: By default, all payload data is sent under
the “json” keyword for your request.
10 Chapter 1. Subpackages
Xpanse, Release 2.1.0
Returns An object containing the raw requests.Response and parsed data results. The raw re-
sponse can be accessed with <xpanse_reponse>.response attribute. The parsed results can
be accessed with the <xpanse_response>.data attribute.
Return type XpanseResponse
Examples
Examples
Examples
xpanse.api.tags.v1.tags module
class TagsEndpoint(session)
Bases: xpanse.endpoint.XpanseEndpoint
Part of the Public API for handling Tags.
ASSIGN_DATA_KEY = 'assign_tags'
ASSIGN_ENDPOINT = 'public_api/v1/assets/tags/{data_type}/assign'
REMOVE_DATA_KEY = 'remove_tags'
REMOVE_ENDPOINT = 'public_api/v1/assets/tags/{data_type}/remove'
assign(data_type: xpanse.const.TaggableDataType, tags: List[str], filters: List[xpanse.types.Filter],
**kwargs) → xpanse.response.XpanseResponse
This method assigns new or existing tags to a set of taggable data.
The two taggable data types are Asset Tags (AT) and IP Range Tags (IPR).
Parameters
• data_type (TaggableDataType) – The data type you would like to tag. Currently
only supports tagging Assets and Owned IP Ranges
• tags (List[str]) – A list of the new or existing tag names you would like to attach.
• filters (List[Filter]) – A list of Filters to determine the filtered set of data to
which the tags should be applied.
• **kwargs – Any extraneous parameters you would like to include when executing your
request with the Requests.request module. Note: By default, all payload data is sent under
the “json” keyword for your request.
Returns An object containing the raw requests.Response and parsed data results. The raw re-
sponse can be accessed with <xpanse_reponse>.response attribute. The parsed results can
be accessed with the <xpanse_response>.data attribute.
Return type XpanseResponse
12 Chapter 1. Subpackages
Xpanse, Release 2.1.0
Examples
>>> # Attach "Awesome Tag" and "Boring Tag" to Asset with ID "abc1":
>>> tags = client.tags.assign(data_type=TaggableDataType.ASSETS,
>>> tags=["Awesome Tag", "Boring Tag"],
>>> filters=[{"field": "asm_id_list", "operator":
˓→"in", "value": ["abc1"]}])
Examples
>>> # Remove "Awesome Tag" and "Boring Tag" to Asset with ID "abc1":
>>> tags = client.tags.remove(data_type=TaggableDataType.ASSETS,
>>> tags=["Awesome Tag", "Boring Tag"],
>>> filters=[{"field": "asm_id_list", "operator":
˓→"in", "value": ["abc1"]}])
class AssetsApi(session)
Bases: xpanse.api.asset_management.v1.assets.AssetsEndpoint
property current_version
property v1
class OwnedIpRangesApi(session)
Bases: xpanse.api.asset_management.v1.owned_ip_ranges.OwnedIpRangesEndpoint
property current_version
property v1
class ServicesApi(session)
Bases: xpanse.api.asset_management.v1.services.ServicesEndpoint
property current_version
property v1
class AttackSurfaceRulesApi(session)
Bases: xpanse.api.attack_surface_rules.v1.attack_surface_rules.
AttackSurfaceRulesEndpoint
property current_version
property v1
class AlertsApi(session)
Bases: xpanse.api.incident_management.v2.alerts.AlertsEndpoint
property current_version
property v1
property v2
class IncidentsApi(session)
Bases: xpanse.api.incident_management.v1.incidents.IncidentsEndpoint
property current_version
property v1
class TagsApi(session)
Bases: xpanse.api.tags.v1.tags.TagsEndpoint
property current_version
property v1
14 Chapter 1. Subpackages
CHAPTER
TWO
SUBMODULES
15
Xpanse, Release 2.1.0
16 Chapter 2. Submodules
CHAPTER
THREE
XPANSE.CLIENT MODULE
17
Xpanse, Release 2.1.0
property alerts
Alerts V2 API
property assets
Assets API
property attack_surface_rules
Attack Surface Rules API
delete(path: str) → Optional[requests.models.Response]
Initiates an HTTP DELETE request using the specified path. Refer to requests.request for more
detailed information on what keyword arguments can be passed:
Parameters
• path (str) – The path to be appended onto the base URL for the request.
• **kwargs (dict) – Keyword arguments to be passed to the Requests Sessions request
method.
Returns requests.Response
get(path: str, **kwargs: Any) → Optional[requests.models.Response]
Initiates an HTTP GET request using the specified path. Refer to requests.request for more detailed
information on what keyword arguments can be passed:
Parameters
• path (str) – The path to be appended onto the base URL for the request.
• **kwargs (dict) – Keyword arguments to be passed to the Requests Sessions request
method.
Returns requests.Response
property incidents
Incidents API
property owned_ip_ranges
Owned IP Ranges API
patch(path: str, **kwargs: Any) → Optional[requests.models.Response]
Initiates an HTTP PATCH request using the specified path. Refer to requests.request for more
detailed information on what keyword arguments can be passed:
Parameters
• path (str) – The path to be appended onto the base URL for the request.
• **kwargs (dict) – Keyword arguments to be passed to the Requests Sessions request
method.
Returns requests.Response
post(path: str, **kwargs: Any) → Optional[requests.models.Response]
Initiates an HTTP POST request using the specified path. Refer to requests.request for more
detailed information on what keyword arguments can be passed:
Parameters
• path (str) – The path to be appended onto the base URL for the request.
• **kwargs (dict) – Keyword arguments to be passed to the Requests Sessions request
method.
Returns requests.Response
19
Xpanse, Release 2.1.0
FOUR
XPANSE.CONST MODULE
class AssetType(value)
Bases: enum.Enum
Enums for Asset Types
CERTIFICATE = 'certificate'
Certificate Type
CLOUD_RESOURCES = 'cloud_compute_instance'
“Cloud Compute Instance Type
DOMAIN = 'domain'
Domain Type
OWNED_RESPONSIVE_IP = 'unassociated_responsive_ip'
Unassociated Responsive IP Type
PRISMA_CLOUD_RESOURCE = 'cloud_integration'
“Cloud Integration Type
CORTEX_API_KEY = 'CORTEX_API_KEY'
Env Variable for Cortex Public API Key
CORTEX_API_KEY_ID = 'CORTEX_API_KEY_ID'
Env Variable for Cortex Public API Key ID
CORTEX_FQDN = 'CORTEX_FQDN'
Env Variable for API Host (Fully Qualified Domain Name)
DEFAULT_REQUEST_PAYLOAD_FIELD = 'json'
Default Parameter Used by the Requests Library for the Payload
DEFAULT_SEARCH_FROM = 0
Default search_from Field for Limit-Offset Pagination
DEFAULT_SEARCH_TO = 100
Default search_to Field for Limit-Offset Pagination
class FilterOperator(value)
Bases: enum.Enum
Enum for Filter Operators
CONTAINS = 'contains'
Contains
EQ = 'eq'
Equals
21
Xpanse, Release 2.1.0
GTE = 'gte'
Greater Than or Equal To
IN = 'in'
Includes
LTE = 'lte'
Less Than or Equal To
NEQ = 'neq'
Not Equals
NIN = 'nin'
Not Includes
NOT_CONTAINS = 'not_contains'
Not Contains
class HTTPVerb(value)
Bases: enum.Enum
Enums for HTTP verbs
HTTP_DELETE = 'DELETE'
HTTP DELETE Verb
HTTP_GET = 'GET'
HTTP GET Verb
HTTP_PATCH = 'PATCH'
HTTP PATCH Verb
HTTP_POST = 'POST'
HTTP POST Verb
HTTP_PUT = 'PUT'
HTTP PUT Verb
MAX_TOTAL_COUNT = 9999
Maximum total_count in the reply for Most Endpoints
class PublicApiFields
Bases: object
Keys for PAPI Requests and Responses
FIELD = 'field'
Common Field For Providing Request Data
FILTERS = 'filters'
Common Field For Providing Request Data
KEYWORD = 'keyword'
Common Field For Sorting Keyword in Request Data
NEXT_PAGE_TOKEN = 'next_page_token'
Common Pagination Token Field
OPERATOR = 'operator'
Common Field For Filter Operator in Request Data
REPLY = 'reply'
Common Top-Level Response Key
REQUEST_DATA = 'request_data'
Common Field For Providing Request Data
RESULTS_COUNT = 'results_count'
Common Field for Page Size Count
SEARCH_FROM = 'search_from'
Common Field For Query Offset
SEARCH_TO = 'search_to'
Common Field For Calculating Query Limit
SORT = 'sort'
Common Field For Sorting in Request Data
TAGS = 'tags'
Common Field For Providing Request Data
TOTAL_COUNT = 'total_count'
Common Field for Total Results Count - Limit is 9,999
USE_PAGE_TOKEN = 'use_page_token'
Common Field To Use Pagination
VALUE = 'value'
Common Field For Filter Value in Request Data
class SortOrder(value)
Bases: enum.Enum
Enum for Sort Order
ASC = 'asc'
Ascending
DESC = 'desc'
Descending
class TaggableDataType(value)
Bases: enum.Enum
An enumeration.
ASSETS = 'assets_internet_exposure'
Asset Data Type for AT Tag Management
OWNED_IP_RANGES = 'external_ip_address_ranges'
Owned IP Range Data Type for IPR Tag Management
V1_PREFIX = 'public_api/v1'
V1 URL Prefix
V2_PREFIX = 'public_api/v2'
V2 URL Prefix
23
Xpanse, Release 2.1.0
FIVE
XPANSE.ENDPOINT MODULE
class XpanseEndpoint(session)
Bases: object
The XpanseEndpoint class is used as a base class for all endpoints. Any additional logic that is desired to be
present on all endpoints, but is outside of the scope of the session or client can be added here.
25
Xpanse, Release 2.1.0
SIX
XPANSE.ERROR MODULE
27
Xpanse, Release 2.1.0
SEVEN
XPANSE.ITERATOR MODULE
class XpanseResultIterator(api: Any, path: str, data_key: str, use_page_token: bool = True,
search_from: int = 0, search_to: int = 100, **kwargs)
Bases: object
Iterator for paging though results.
dump() → List[Any]
Iterates until completion and returns a list of results.
has_next() → bool
True when there’s another page of data, False when pagination is complete.
next() → Dict[str, Any]
Fetches the result from pagination.next, if a value exists.
property total
Returns the total number of results. (Max for most data types is 9_999).
29
Xpanse, Release 2.1.0
EIGHT
XPANSE.RESPONSE MODULE
Examples
property data
Parses the response body and returns it under the data property
property response
Defines the raw requests.Response property
31
Xpanse, Release 2.1.0
NINE
XPANSE.TYPES MODULE
33
Xpanse, Release 2.1.0
TEN
XPANSE.UTILS MODULE
35
Xpanse, Release 2.1.0
ELEVEN
37
Xpanse, Release 2.1.0
11.1 Overview
11.2 Install
11.3 Requirements
Python 3.7+
11.4 Usage
# Import client
from xpanse.client import XpanseClient
# Initialize client
client = XpanseClient()
11.5 Configuration
A valid API Key, API Key ID, and Fully Qualified Domain Name (FQDN) are required for use.
Reference the docs for more information with Getting Started.
RECOMMENDED
You can supply them as environment variables.
NOT RECOMMENDED
The following parameters can be set inline using the XpanseClient constructor.
This is not recommended, as it easily exposes sensitive credentials in your source code.
# Import client
from xpanse.client import XpanseClient
11.6 Logging
Logging is handled through the python logging package. To enable different levels of verbosity in your scripts you
can do the following:
import logging
11.6. Logging 39
Xpanse, Release 2.1.0
x
xpanse.api.asset_management, 13
xpanse.api.asset_management.v1.assets,
1
xpanse.api.asset_management.v1.owned_ip_ranges,
3
xpanse.api.asset_management.v1.services,
4
xpanse.api.attack_surface_rules, 14
xpanse.api.attack_surface_rules.v1.attack_surface_rules,
6
xpanse.api.incident_management, 14
xpanse.api.incident_management.v1.incidents,
8
xpanse.api.incident_management.v2.alerts,
10
xpanse.api.tags, 14
xpanse.api.tags.v1.tags, 12
xpanse.client, 17
xpanse.const, 21
xpanse.endpoint, 25
xpanse.error, 27
xpanse.iterator, 29
xpanse.response, 31
xpanse.types, 33
xpanse.utils, 35
41
Xpanse, Release 2.1.0
C F
CERTIFICATE (AssetType attribute), 21 field (Filter attribute), 33
CLOUD_RESOURCES (AssetType attribute), 21 FIELD (PublicApiFields attribute), 22
CONTAINS (FilterOperator attribute), 21 field (Sort attribute), 33
CORTEX_API_KEY (in module xpanse.const), 21 Filter (class in xpanse.types), 33
CORTEX_API_KEY_ID (in module xpanse.const), 21 FilterOperator (class in xpanse.const), 21
CORTEX_FQDN (in module xpanse.const), 21 FILTERS (PublicApiFields attribute), 22
count() (AlertsEndpoint method), 10 filters (RequestData attribute), 33
count() (AssetsEndpoint method), 1
count() (AttackSurfaceRulesEndpoint method), 6 G
count() (IncidentsEndpoint method), 8 get() (AlertsEndpoint method), 11
count() (OwnedIpRangesEndpoint method), 3 get() (AssetsEndpoint method), 2
43
Xpanse, Release 2.1.0
44 Index
Xpanse, Release 2.1.0
Index 45