code: def zlib_compress(data):
      
      if PY3K:
          if isinstance(data, str):
              return zlib.compress(bytes(data, 'utf-8'))
          return zlib.compress(data)
      return zlib.compress(data)
docs: Compress things in a py2/3 safe fashion
      >>> json_str = '{"test": 1}'
      >>> blob = zlib_compress(json_str)