Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8485269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:35:43+00:00 2026-06-10T20:35:43+00:00

I’m assigning all my MongoDB documents a GUID using uuid.uuid1(). I want a way

  • 0

I’m assigning all my MongoDB documents a GUID using uuid.uuid1(). I want a way I can derive an 11 character, unique, case-sensitive YouTube-like ID, such as

1_XmY09uRJ4 

from uuid’s resulting hex string which looks like

ae0a0c98-f1e5-11e1-9t2b-1231381dac60

I want to be able to match the shortened ID to the hex and vice-versa, dynamically without having to store another string in the database. Does anyone have some sample code or can point me in the direction of the module or formula that can do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:35:45+00:00Added an answer on June 10, 2026 at 8:35 pm

    Convert the underlying bytes to a base64 value, stripping the = padding and the newline.

    You probably want to use the base64.urlsafe_b64encode() function to avoid using / and + (_ and - are used instead), so the resulting string can be used as a URL path element:

    >>> import uuid, base64
    >>> base64.urlsafe_b64encode(uuid.uuid1().bytes).rstrip(b'=').decode('ascii')
    '81CMD_bOEeGbPwAjMtYnhg'
    

    The reverse:

    >>> uuid.UUID(bytes=base64.urlsafe_b64decode('81CMD_bOEeGbPwAjMtYnhg' + '=='))
    UUID('f3508c0f-f6ce-11e1-9b3f-002332d62786')
    

    To turn that into generic functions:

    from base64 import urlsafe_b64decode, urlsafe_b64encode
    from uuid import UUID
    
    def uuid2slug(uuidstring):
        return urlsafe_b64encode(UUID(uuidstring).bytes).rstrip(b'=').decode('ascii')
    
    def slug2uuid(slug):
        return str(UUID(bytes=urlsafe_b64decode(slug + '==')))
    

    This gives you a method to represent the 16-byte UUID in a more compact form. Compress any further and you loose information, which means you cannot decompress it again to the full UUID. The full range of values that 16 bytes can represent will never fit it anything less than 22 base64 characters, which needs 4 characters for every three bytes of input and every character encodes 6 bits of information.

    YouTube’s unique string is thus not based on a full 16-byte UUID, their 11 character ids are probably stored in the database for easy lookup and based on a smaller value; e.g. if the value is also a URL-safe base64 string then they encode an 8-byte number.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.