code: def try_convert(value, datetime_to_ms=False, precise=False):
      
      if not isinstance(value, basestring):
          return value
      if value in db.YES_VALUES or value in db.TRUE_VALUES:
          return True
      elif value in db.NO_VALUES or value in db.FALSE_VALUES:
          return False
      elif value in db.NULL_VALUES:
          return None
      try:
          if not precise:
              try:
                  return int(value)
              except:
                  try:
                      return float(value)
                  except:
                      pass
          else:
              dec, i, f = None, None, None
              try:
                  dec = Decimal(value)
              except:
                  return try_convert(value, precise=False)
              try:
                  i = int(value)
              except:
                  try:
                      f = float(value)
                  except:
                      pass
              if dec is not None:
                  if dec == i:
                      return i
                  elif dec == f:
                      return f
                  return dec
      except:
          pass
      try:
          dt = dateutil.parse(value)
          if dt and isinstance(dt, datetime.datetime) and (3000 >= dt.year >= 1900):
              if datetime_to_ms:
                  return db.datetime_in_milliseconds(dt)
              return dt
      except:
          pass
      return value
docs: Convert a str into more useful python type (datetime, float, int, bool), if possible
  
      Some precision may be lost (e.g. Decimal converted to a float)
  
      >>> try_convert('false')
      False
      >>> try_convert('123456789.123456')
      123456789.123456
      >>> try_convert('1234')
      1234
      >>> try_convert(1234)
      1234
      >>> try_convert(['1234'])
      ['1234']
      >>> try_convert('12345678901234567890123456789012345678901234567890', precise=True)
      12345678901234567890123456789012345678901234567890L
      >>> try_convert('12345678901234567890123456789012345678901234567890.1', precise=True)
      Decimal('12345678901234567890123456789012345678901234567890.1')