code: def encode(obj, outtype='json', raise_error=False):
      
      for encoder in get_plugins('encoders').values():
          if (isinstance(obj, encoder.objclass)
                  and hasattr(encoder, 'to_{}'.format(outtype))):
              return getattr(encoder, 'to_{}'.format(outtype))(obj)
              break
  
      if raise_error:
          raise ValueError(
              "No JSON serializer is available for"
              "{0} (of type {1})".format(obj, type(obj)))
      else:
          return obj
docs: encode objects, via encoder plugins, to new types
  
      Parameters
      ----------
      outtype: str
          use encoder method to_<outtype> to encode
      raise_error : bool
          if True, raise ValueError if no suitable plugin found
  
      Examples
      --------
      >>> load_builtin_plugins('encoders')
      []
  
      >>> from decimal import Decimal
      >>> encode(Decimal('1.3425345'))
      {'_python_Decimal_': '1.3425345'}
      >>> encode(Decimal('1.3425345'),outtype='str')
      '1.3425345'
  
      >>> encode(set([1,2,3,4,4]))
      {'_python_set_': [1, 2, 3, 4]}
      >>> encode(set([1,2,3,4,4]),outtype='str')
      '{1, 2, 3, 4}'
  
      >>> unload_all_plugins()