Skip to content

Python API

This package is built around two core analysis workflows in arcgis_dependency._main:

  • interrogate_item_dependencies(...): Given one or more item IDs, returns recursive dependency relationships (or writes an Excel workbook).
  • interrogate_parent_dependency_impact(...): Given one or more target item IDs, returns delete-impact analysis with detailed rows and per-target tri-state decisions (or writes an Excel workbook).

Core Analysis Workflows

arcgis_dependency

interrogate_item_dependencies(item_ids=None, gis=None, output_excel=None)

Interrogate ArcGIS item dependencies for one or more item IDs.

Parameters:

Name Type Description Default
item_ids str | list[str] | None

Single item ID, list of item IDs, or None to resolve from configuration.

None
gis GIS | None

Optional pre-built ArcGIS GIS instance to use instead of constructing one from project configuration.

None
output_excel str | Path | None

Optional workbook path. When provided, results are written to Excel and the written path is returned.

None

Returns:

Type Description
DataFrame | Path

pandas.DataFrame | Path: Dependency table by default, or the written

DataFrame | Path

workbook path when output_excel is provided.

Raises:

Type Description
ValueError

If no usable item IDs or GIS connection settings are found.

RuntimeError

If item interrogation fails unexpectedly.

interrogate_parent_dependency_impact(target_item_ids=None, gis=None, output_excel=None)

Interrogate parent-impact by finding what items are affected by deleting targets.

Parameters:

Name Type Description Default
target_item_ids str | list[str] | None

Single target ID, list of target IDs, or None to resolve from config request_item_ids.

None
gis GIS | None

Optional pre-built ArcGIS GIS instance. When provided, config-based GIS construction is skipped.

None
output_excel str | Path | None

Optional workbook path. When provided, writes two sheets: impact_rows and target_decisions.

None

Returns:

Type Description
dict[str, DataFrame] | Path

dict[str, pandas.DataFrame] | Path: A dictionary containing

dict[str, DataFrame] | Path

impact_rows and target_decisions DataFrames by default, or the

dict[str, DataFrame] | Path

written workbook path when output_excel is provided.

Raises:

Type Description
ValueError

If no usable target IDs or GIS settings are available.

RuntimeError

If an unexpected error prevents analysis completion.

Supporting Configuration

arcgis_dependency.config

Configuration loader for the project.

Reads settings from YAML configuration files in the config/ directory using a singleton pattern so the files are parsed once and reused across modules.

The YAML config supports environment-specific sections defined under the environments key in config.yml. A special default sub-section provides fallback values for any key that is not overridden in a named environment. The merge order is:

  1. Top-level keys in config.yml
  2. environments.default (if present) — overrides top-level defaults
  3. environments.<active-env> — overrides both of the above

Add, rename, or remove environments by editing that YAML block — no Python changes required. Set the ENVIRONMENT environment variable to force the active environment, otherwise the environment key in config.yml is used, and the function invocation parameter is used as a final fallback.

Usage::

from arcgis_dependency.config import config, ENVIRONMENT

# dot-notation access
log_level = config.logging.level

# dict-style access
input_path = config["data"]["input"]

# secrets are merged into config — no separate namespace
gis_url = config.esri.gis_url

# check current environment
print(f"Running in {ENVIRONMENT} mode")

ConfigNode

Immutable, attribute-accessible wrapper around nested dictionaries.

Supports both dot-notation (cfg.logging.level) and dict-style (cfg["logging"]["level"]) access for convenience.

get(key, default=None)

Return the value for key if present, else default.

to_dict()

Recursively convert back to a plain dictionary.

get_available_environments(config_path=None)

Return the named environment keys defined in config.yml.

The reserved default key is excluded from the result because it is a fallback section, not a selectable environment.

Parameters

config_path : Path or str, optional Explicit path to a YAML file. Defaults to config/config.yml.

Returns

list[str] Sorted list of environment keys found under the environments section, excluding default (e.g. ["dev", "prod", "test"]).

load_config(config_path=None, environment=None)

Load the main project configuration for a given environment.

Configuration is built up in three layers:

  1. Top-level keys (e.g. project) — always included.
  2. environments.default — deep-merged on top of the top-level keys, providing shared fallback values for all environments.
  3. environments.<env> — deep-merged last, overriding both of the above with environment-specific values.

Any key present in default but absent from the active environment section is inherited from default. Keys present in the active environment always win.

Available environments are introspected from the environments key in config.yml (excluding the reserved default key) — add or remove named sections there to define your own.

Parameters

config_path : Path or str, optional Explicit path to a YAML file. Defaults to config/config.yml relative to the project root. environment : str, optional Environment name passed at invocation time. Resolution order is: ENVIRONMENT environment variable, then top-level environment in config.yml, then this parameter.

Returns

ConfigNode A recursively accessible configuration object.

Raises

ValueError If the requested environment is not defined in config.yml.

load_secrets(secrets_path=None, environment=None)

Load and resolve project secrets for the given environment.

Applies the same three-layer merge used by :func:load_config:

  1. Top-level keys in secrets.yml
  2. environments.default — shared fallback values shared across all environments.
  3. environments.<env> — environment-specific overrides applied last.

The resolved secrets are deep-merged into the main config object so they are accessible as config.esri.gis_url — no separate namespace.

Unlike :func:load_config, a missing environment section in secrets.yml is not an error: the file may legitimately omit environments that require no overrides beyond the default values. A debug message is emitted if the active environment is not found.

Parameters

secrets_path : Path or str, optional Explicit path to a YAML file. Defaults to config/secrets.yml relative to the project root. environment : str, optional Environment name passed at invocation time. Resolution order is: ENVIRONMENT environment variable, then top-level environment in config.yml, then this parameter.

Returns

ConfigNode A recursively accessible, environment-resolved secrets object. The result is merged into the main :pydata:config singleton — do not use it as a standalone secrets store.

Raises

FileNotFoundError If the secrets file does not exist. Copy config/secrets_template.yml to config/secrets.yml and fill in your values.

Supporting Utilities

arcgis_dependency.utils

format_df_for_logging(pandas_df, title, line_tab_prefix='\t\t')

Helper function facilitating outputting a Pandas DataFrame into a logfile. This function only formats the data frame into text for output. It should be used in conjunction with a logging method.

logging.info(format_df_for_logging(df, title='Summary Statistics'))

Parameters:

Name Type Description Default
pandas_df DataFrame

Pandas DataFrame to be converted to a string and included in the logfile.

required
title str

String title describing the data frame.

required
line_tab_prefix str

Optional string comprised of tabs (\t\t) to prefix each line with providing indentation.

'\t\t'

get_logger(logger_name=None, level='INFO', logfile_path=None, log_format='%(asctime)s | %(name)s | %(levelname)s | %(message)s', propagate=True, add_stream_handler=False)

Get Python logging.Logger configured to provide stream, file or, if available, ArcPy output. The way the method is set up, logging will be routed through ArcPy messaging using ArcpyHandler if ArcPy is available. If ArcPy is not available, messages will be sent to the console using a logging.StreamHandler. Next, if the logfile_path is provided, log messages will also be written to the provided path to a logfile using a logging.FileHandler.

Valid log_level inputs include: * DEBUG - Detailed information, typically of interest only when diagnosing problems. * INFO - Confirmation that things are working as expected. * WARNING or WARN - An indication that something unexpected happened, or indicative of some problem in the near future (e.g. "disk space low"). The software is still working as expected. * ERROR - Due to a more serious problem, the software has not been able to perform some function. * CRITICAL - A serious error, indicating that the program itself may be unable to continue running.

Note

Logging levels can be provided as strings (e.g. 'DEBUG'), corresponding integer values or using the logging module constants (e.g. logging.DEBUG).

Parameters:

Name Type Description Default
logger_name Optional[str]

Name of the logger. If None, the root logger is used.

None
level Optional[Union[str, int]]

Logging level to use. Default is INFO.

'INFO'
log_format Optional[str]

Format string for the logging messages. Default is '%(asctime)s | %(name)s | %(levelname)s | %(message)s'.

'%(asctime)s | %(name)s | %(levelname)s | %(message)s'
propagate bool

If True, log messages are passed to the handlers of ancestor loggers. Default is False.

True
logfile_path Optional[Union[Path, str]]

Where to save the logfile if file output is desired.

None
add_stream_handler bool

If True, add a StreamHandler to route logging to the console. Default is False.

False
logger = get_logger('DEBUG')
logger.debug('nauseatingly detailed debugging message')
logger.info('something actually useful to know')
logger.warning('The sky may be falling')
logger.error('The sky is falling.')
logger.critical('The sky appears to be falling because a giant meteor is colliding with the earth.')