Skip to main content

QRadar client for python with API schema fetching

Project description

QRadar API python client for scripting

[!IMPORTANT] python3.10 and above supported.

http libs such as requests or httpx should be installed separately or as optional packages, as described below.

Features:

  • Pulls API schema from QRadar and creates client methods dynamically for the API version specified. This makes this client source code as small as possible;
  • Asyncronous and client with schema caching introduced
  • All the endpoints of QRadar API is mapped to a client method by name;
  • No dependencies introduced, tested with httpx and requests http protocol libs with dependency injection, but obviously will only work with libs that provide compatible requests-like interface for Session-like object. Of course, wrappers can help with using incompatible libs;
  • Generates stub file for method hinting if needed. It takes ~10MB of disk space.

Installation

pip install qradar

or with requests/httpx correspondingly:

pip install qradar[requests]

pip install qradar[httpx]

Intended usage

[!TIP] Made to be used as full-featured copypaste drop-in client for scripts where pip installation way be unwanted. Clients are used this way in examples.

Of course, it is not prohibited to install this package with pip.

How to use any client (refer to examples for more)

  1. Use any of import statements:
from qradar import QRadar, QRadarAsync, QRadarCached

or copy the coppersonding qradar/client.py file contents

  1. Initialize client as following:
q = QRadar("https://qradar.is.local", KEY, "22.0", requests.Session(), verify=False) 

Having:

  • qradar.is.local is QRadar console hostname or ip
  • KEY is API key created from console
  • "22.0" - replaced with API version you want
  • requests imported (and installed)

Also works with httpx, with minor differences. Refer to examples for details

  1. Use client instance methods, forming the name of desired endpoint

For example, the endpoint 22.0 - GET - /reference_data/map_of_sets is referenced by name q.get_reference_data_map_of_sets. The http method goes first, and the API endpoint path is trailing it, having the slashes replaced with underscores.

For endpoints such as 22.0 - GET - /reference_data/map_of_sets/{name} use the reference_data_map_of_sets_name, with {name} part provided as keyword argument: q.get_reference_data_map_of_sets_name(name='refmapofsetsname')

For params such as filter, use keyword arguments: q.help_endpoint(filter=f"version={version}")

For data posting, use first non-keyword argument. It accepts json-serializable objects (lists, dicts, lists of dicts, etc.): q.post_reference_data_map_of_sets({"data": ["data"]})

Generating .pyi file for intellisense

[!IMPORTANT] This option may be used for setting up more convenient development environment. Final script version should be delivered without API schema.

  1. Clone the repository into project folder
  2. Run python3 schema_prefetch.py having correct parameters in source code
  3. client.pyi file must appear. As far as it is in one folder with client.py, the methods will be hinted with the names, arguments and description from QRadar API schema

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

qradar-0.0.3.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qradar-0.0.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file qradar-0.0.3.tar.gz.

File metadata

  • Download URL: qradar-0.0.3.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for qradar-0.0.3.tar.gz
Algorithm Hash digest
SHA256 61fcebf1fb570dfa71c96faec82ce61650bd87017bb2370b7374209d94c3f8b3
MD5 4a0b42a8adb7658edc6a8400f0052fa0
BLAKE2b-256 bb364815558dd7b068913b00f0ee336298a36b0505f042a290bf72f8ceb0486e

See more details on using hashes here.

File details

Details for the file qradar-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: qradar-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for qradar-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2c4d9ab75a857f917a39730bb334521e261e6aef67090549651098b9d0a88bc0
MD5 6fd89e01a98a882296a286ee97aaecec
BLAKE2b-256 f76f0cdc4633fc9908524769a3c07c3603d6e93dadc2673cb23244668592fbcd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page