Profiles

Profile management for multi-environment configurations

Simple profile management for NiPyAPI development configurations.

nipyapi.profiles.current()[source]

Show the currently configured endpoints.

Returns:

Current endpoint configuration.

Return type:

dict

nipyapi.profiles.get_default_profile_name()[source]

Get the first profile name from the profiles file.

Resolution order:
  1. NIPYAPI_PROFILES_FILE environment variable

  2. ~/.nipyapi/profiles.yml (user-level config)

Returns:

Profile name, or None if no profiles file exists

Return type:

str

nipyapi.profiles.list_profiles(profiles_file=None)[source]

List available profile names from the profiles file.

Parameters:

profiles_file (str, optional) – Path to profiles file. Uses default resolution if None.

Returns:

Profile names available in the profiles file.

Return type:

list

nipyapi.profiles.load_profiles_from_file(file_path=None)[source]

Load profile configurations from a YAML or JSON file.

Supports both YAML and JSON formats since JSON is a subset of YAML syntax.

Parameters:

file_path (str, optional) – Path to YAML or JSON file containing profile definitions. If None, resolves using: 1. NIPYAPI_PROFILES_FILE environment variable 2. ~/.nipyapi/profiles.yml (user-level config) 3. nipyapi.config.default_profiles_file (development fallback)

Returns:

Profile configurations

Return type:

dict

nipyapi.profiles.resolve_profile_config(profile_name, profiles_file_path=None)[source]

Complete profile configuration resolution with environment overrides and absolute paths.

Supports both simple shared certificates and complex per-service PKI configurations. Accepts both YAML and JSON profile files.

Special “env” profile: When profile_name is “env”, configuration is loaded entirely from environment variables without requiring a profiles file. This is useful for CI/CD pipelines and containerized deployments where all configuration comes from the environment.

Parameters:
  • profile_name (str) – Name of profile to resolve. Use “env” for pure environment variable configuration without a profiles file.

  • profiles_file_path (str, optional) – Path to profiles YAML or JSON file. Default resolution handled by load_profiles_from_file(). Ignored when profile_name is “env”.

Returns:

Fully resolved configuration with all paths and overrides applied

Return type:

dict

nipyapi.profiles.show(profile_name, profiles_file=None, mask_secrets=True)[source]

Show a profile’s resolved configuration.

Parameters:
  • profile_name (str) – Name of the profile to show.

  • profiles_file (str, optional) – Path to profiles file. Uses default resolution if None.

  • mask_secrets (bool) – If True, mask sensitive values. Defaults to True.

Returns:

Profile configuration with secrets optionally masked.

Return type:

dict

nipyapi.profiles.switch(profile_name=None, profiles_file=None, login=True)[source]

Switch to a different profile at runtime using configuration-driven authentication.

Automatically detects authentication methods based on available configuration parameters rather than profile names, making it flexible for custom profiles.

Supports OIDC (requires oidc_token_endpoint, oidc_client_id, oidc_client_secret), mTLS (requires client_cert, client_key), and Basic auth (requires nifi_user/nifi_pass).

Parameters:
  • profile_name (str, optional) – Profile to switch to. None auto-resolves from env vars or profiles file. “env” uses explicit environment variables. Any other string uses that named profile from the profiles file.

  • profiles_file (str, optional) – Path to profiles file. Defaults to NIPYAPI_PROFILES_FILE env var or nipyapi.config.default_profiles_file.

  • login (bool, optional) – Whether to attempt authentication. Defaults to True. If False, configures SSL/endpoints but skips login attempts.

Returns:

OIDC returns token_data dict, Basic returns username string, mTLS and login=False return None.

Return type:

tuple of (profile_name, metadata). Metadata varies by auth method

Raises:

ValueError – If profile not found or required authentication parameters are missing

Example:

>>> import nipyapi.profiles
>>> nipyapi.profiles.switch()  # Auto-resolve: env vars or user profile
>>> nipyapi.profiles.switch('single-user')  # Uses basic auth
>>> nipyapi.profiles.switch('secure-mtls')  # Uses mTLS auth
>>> nipyapi.profiles.switch('secure-oidc')  # Uses OIDC auth
>>> nipyapi.profiles.switch('my-custom')    # Uses whatever auth method is configured
>>>
>>> # Explicit environment variable mode for CI/CD (strict - fails if not set)
>>> nipyapi.profiles.switch('env')
>>>
>>> # Custom profiles file
>>> nipyapi.profiles.switch('production',
...                          profiles_file='/home/user/.nipyapi/profiles.yml')