code: def from_bytes(key_bytes):
          
          b = get_bytes(key_bytes)
          key_bytes_len = len(b)
  
          key_type = b[0]
          if key_type == 0x04:
              # Uncompressed
              if key_bytes_len != 65:
                  raise ValueError("key_bytes must be exactly 65 bytes long when uncompressed.")
  
              x = int.from_bytes(b[1:33], 'big')
              y = int.from_bytes(b[33:65], 'big')
          elif key_type == 0x02 or key_type == 0x03:
              if key_bytes_len != 33:
                  raise ValueError("key_bytes must be exactly 33 bytes long when compressed.")
  
              x = int.from_bytes(b[1:33], 'big')
              ys = bitcoin_curve.y_from_x(x)
  
              # Pick the one that corresponds to key_type
              last_bit = key_type - 0x2
              for y in ys:
                  if y & 0x1 == last_bit:
                      break
          else:
              return None
  
          return PublicKey(x, y)
docs: Generates a public key object from a byte (or hex) string.
  
          The byte stream must be of the SEC variety
          (http://www.secg.org/): beginning with a single byte telling
          what key representation follows. A full, uncompressed key
          is represented by: 0x04 followed by 64 bytes containing
          the x and y components of the point. For compressed keys
          with an even y component, 0x02 is followed by 32 bytes
          containing the x component. For compressed keys with an
          odd y component, 0x03 is followed by 32 bytes containing
          the x component.
  
          Args:
              key_bytes (bytes or str): A byte stream that conforms to the above.
  
          Returns:
              PublicKey: A PublicKey object.