Skip to content

Netlas Python SDK

The Netlas Python SDK is a software development kit provided by the Netlas team to facilitate the integration of Netlas services into Python applications.

The SDK provides a convenient way to interact with the API, performing tasks such as queries routing and parsing the JSON responses from the Netlas API into Python objects, simplifying the process of integrating Netlas data into Python projects.

Important

The SDK does not handle errors and request throttling. The developer must provide handling of these exceptions.

Installation

If you have Python installed, simply use the Python package installer to install the SDK:

$ pip install netlas

Or if you already have it installed and want to upgrade to the latest version:

$ pip install --upgrade netlas

Usage sample

The following code sample routes the request port:7001 to the Netlas response search and prints search results to stdout.

import netlas

apikey = "YOUR_API_KEY"

# create new connection to Netlas
netlas_connection = netlas.Netlas(api_key=apikey)

# retrieve data from responses by query `port:7001`
netlas_query = netlas_connection.query(query="port:7001")

# iterate over data and print: IP address, port, path and protocol
for response in netlas_query['items']:
    print(f"{response['data']['ip']}:{response['data']['port']}{response['data']['path']} [{response['data']['protocol']}]")
pass

SDK classes specification

Below is documentation on the main classes and their methods included in Netlas SDK.

Netlas

__init__(api_key='', apibase='https://app.netlas.io', debug=False)

Netlas class constructor

Parameters:

Name Type Description Default
api_key str

Personal API key, defaults to ""

''
apibase str

Netlas API server address, defaults to "https://app.netlas.io"

'https://app.netlas.io'
debug bool

Debug flag, defaults to False

False

count(query, datatype='response', indices='')

Calculate total count of query string results

Parameters:

Name Type Description Default
query str

Search query string

required
datatype str

Data type (choises: response, cert, domain, whois-ip, whois-domain), defaults to "response"

'response'
indices str

Comma-separated IDs of selected data indices (can be retrieved by indices method), defaults to ""

''

Returns:

Type Description
dict

JSON object with total count of query string results

download(query, fields=None, exclude_fields=False, datatype='response', size=10, indices='')

Download data from Netlas

Parameters:

Name Type Description Default
query str

Search query string

required
fields str

Comma-separated list of fields to include/exclude, default: all fields

None
exclude_fields bool

Exclude fields from output (instead include), defaults to False

False
datatype str

Data type (choices: response, cert, domain, whois-ip, whois-domain), defaults to "response"

'response'
size int

Download documents count, defaults to 10

10
indices str

Comma-separated IDs of selected data indices (can be retrieved by indices method), defaults to ""

''

Returns:

Type Description
Iterator[bytes]

Iterator of raw data

host(host, fields=None, exclude_fields=False)

Get full information about host (ip or domain)

Parameters:

Name Type Description Default
host str

IP or domain string

required
fields str

Comma-separated output fields. If empty it will output all data

None

Returns:

Type Description
dict

JSON object with full information about host

indices()

Get available data indices

Returns:

Type Description
list

List of available indices

profile()

Get user profile data

Returns:

Type Description
dict

JSON object with user profile data

search(query, datatype='response', page=0, indices='', fields=None, exclude_fields=False)

Send search query to Netlas API

Parameters:

Name Type Description Default
query str

Search query string

required
datatype str

Data type (choises: response, cert, domain, whois-ip, whois-domain), defaults to "response"

'response'
page int

Page number of data, defaults to 0

0
indices str

Comma-separated IDs of selected data indices (can be retrieved by indices method), defaults to ""

''
fields str

Comma-separated list of fields to include/exclude, default: all fields

None
exclude_fields bool

Exclude fields from output (instead include), defaults to False

False

Returns:

Type Description
dict

search query result

stat(query, group_fields, indices='', size=100, index_type='responses')

Get statistics of responses query string results

Parameters:

Name Type Description Default
query str

Search query string

required
group_fields str

Comma-separated fields using for aggregate data

required
indices str

Comma-separated IDs of selected data indices (can be retrieved by indices method), defaults to ""

''
size int

Aggregation size, default 100

100
index_type str

Index type (choises: responses, certificates, domains), defaults to "responses"

'responses'

Returns:

Type Description
dict

JSON object with statistics of responses query string results

APIError

Bases: Exception

Basic Netlas.io Exception class