I don't know how to check if a variable is primitive. In Java it's like this:
if var.isPrimitive():
isinstance(obj, (str, numbers.Number) should be close enough:
isinstance(obj, (str, numbers.Number)