def partial_format(target, **kwargs):
  """Formats a string without requiring all values to be present.

  This function allows substitutions to be gradually made in several steps
  rather than all at once.  Similar to string.Template.safe_substitute.
  """
  output = target[:]

  for tag, var in re.findall(r'(\{(.*?)\})', output):
    root = var.split('.')[0]  # dot notation
    root = root.split('[')[0]  # dict notation
    if root in kwargs:
      output = output.replace(tag, tag.format(**{root: kwargs[root]}))

  return output
Formats a string without requiring all values to be present.

  This function allows substitutions to be gradually made in several steps
  rather than all at once.  Similar to string.Template.safe_substitute.