Getting Started

To use the BlastLogic Extend package, you must have the following essential components available:

  • BlastLogic Server 2024 or later

    • The BlastLogic Extend API was first introduced in BlastLogic 2024 to integrate third party systems, custom software, scripts and tools with the BlastLogic ecosystem.

  • Be licensed for BlastLogic Extend.

    • Contact Maptek for licensing enquiries.

  • A Python interpreter.

  • The Wheel (package) for BlastLogic Extend

    • It is available from PyPi <https://pypi.org/project/maptekblastlogic/> - the Python package index which is an online service that provides the ability to find and install Python packages.

  • A code editor to edit Python Scripts.

    • You can use any text editor to write Python, but we highly recommend using Visual Studio Code.

A basic understand of Python is expected:

  • Functions

  • Classes

  • Imports

Installation

It is recommended that you create a virtual environment for this project. The key benefit of this is it ensures the dependencies of this project don’t interfere with other projects and they don’t interfere with this one. See Create and Use Virtual Environments in the Python packaging user Guide for details. This is especially important if you are working on Linux as distributions often manage their own packages for Python and a virtual environment prevents the two sources of Packages from conflicting.

If you are working in a virtual environment:

python -m pip install maptekblastlogic

Configuration

In order to be able to use the BlastLogic Extend API, an API key needs to be generated for the BlastLogic server that you want the script to connect to.

The API key is like a username and password which authenticates your requests with the BlastLogic server.

Log into the web interface for BlastLogic Server and click on “User Keys”. On this page click the “New” button to generate a key.

When creating the key, provide a useful description so you know what the key is for, such as saying “Python Blast Truck Integration”. If you are not sure, consider “Python Experiment”.

Copy the key to your password manager. The server will only display the key once. If the key is lost, you will need to delete it and create a new one.

WARNING Do not store the API key within the Python script itself.

Doing this means anyone you share the script with will be able to interact with the BlastLogic Server as you. Read it from another file or from a password storage service.

Example Script

The following can be used to test that the package was installed and the API key is set-up. It can also be used as a starting point for your script.

The script uses Python’s built in getpass library to provide a prompt on the command line where the user can enter their token. It is more robust to use the 3rd party keyring package to securely store your key.

Once you have generated the key, you will need to create an AuthenticatedClient object to connect the Python Script to the server:

"""Prints sites on a BlastLogic server."""
import getpass
from maptekblastlogic import AuthenticatedClient
from maptekblastlogic.models import ErrorModel

token = getpass.getpass("Token for BlastLogic server:")
with AuthenticatedClient(
   base_url="http://blastlogic/50/api",
   raise_on_unexpected_status=True,
   token=token,
) as client:
   sites = get_sites.sync(client=client)
   if isinstance(sites, ErrorModel):
      raise RuntimeError(
            "Error when reading sites:",
            sites.title,
            "\n",
            sites.details,
      )
   if not sites:
      raise RuntimeError("No sites found on server.")

   for site in sites or []:
      if not site.is_active:
            print(f"Skipping. Site '{site.name}' is not active.")
            continue
      print(site.name, site.site_code)
  • The first lines import packages (libraries) to be used in the script. This is common for Python scripts.

  • The getpass.getpass() line causes the script to ask for an API token.

  • The client is set-up with the token and the URL to the BlastLogic server to connect to. This needs to be replaced with the URL of the server that you have access to.

  • Next the list of sites is requested.

  • If there are no sites, it raises an error to inform the user.

  • Otherwise, for each site, it prints out the name and site code if it is active.