def import_py(lib, name, args, ret, defs=None, echk=None):
  """ Import a native function.
  Args:
    lib  Library to load from
    name Function name in the library
    args List of argument classes
    ret  Return value class
    defs Defaulted tuple of last parameters
    echk Optional filter/error checking function
  Returns:
    Function instance
  """
  # Assertions
  if defs is not None:
    assert isinstance(defs, tuple), "Expected a 'tuple' for argument 'defs'"
    assert len(defs) <= len(args), "More defaults provided than possible arguments"
  # Import and declaration
  func = getattr(lib, name, None)
  if func is None:
    raise RuntimeError("Function " + repr(name) + " is not exported in " + repr(lib._name))
  func.argtypes = args
  func.rettype = ret
  # Optional error check
  if echk is not None:
    func.errcheck = echk
  # Application of the optional parameters
  if defs is None:
    return func
  else:
    def call(*curr):
      """ Call 'func', replacing missing and defaulted arguments.
      Args:
        ... Forwarded arguments
      Returns:
        Forwarded returned value
      """
      assert len(args) <= len(curr) + len(defs), "Not enough parameters provided in native function call"
      return func(*(curr + defs[len(curr) - len(args) + len(defs):]))
    return call