title: How can I determine the byte length of a utf-8 encoded string in Python?
body: <p>I am working with Amazon S3 uploads and am having trouble with key names being too long.  S3 limits the length of the key by bytes, not characters.</p>
  
  <p>From the docs:</p>
  
  <blockquote>
    <p>The name for a key is a sequence of Unicode characters whose UTF-8 encoding is at most 1024 bytes long. </p>
  </blockquote>
  
  <p>I also attempt to embed metadata in the file name, so I need to be able to calculate the current byte length of the string using Python to make sure the metadata does not make the key too long (in which case I would have to use a separate metadata file).</p>
  
  <p>How can I determine the byte length of the utf-8 encoded string?  Again, I am not interested in the character length... rather the actual byte length used to store the string.</p>