Giter Site home page Giter Site logo

py-nanoid's Introduction

Nano ID

CircleCI

A tiny, secure, URL-friendly, unique string ID generator for Python.

  • Safe. It uses cryptographically strong random APIs and tests distribution of symbols.
  • Compact. It uses a larger alphabet than UUID (A-Za-z0-9_-). So ID size was reduced from 36 to 21 symbols.

Installation

pip install nanoid

Usage

Normal

The main module uses URL-friendly symbols (A-Za-z0-9_-) and returns an ID with 21 characters (to have a collision probability similar to UUID v4).

from nanoid import generate

generate() # => NDzkGoTCdRcaRyt7GOepg

Symbols -,.() are not encoded in the URL. If used at the end of a link they could be identified as a punctuation symbol.

If you want to reduce ID length (and increase collisions probability), you can pass the length as an argument.

from nanoid import generate

generate(size=10) # => "IRFa-VaY2b"

Don’t forget to check the safety of your ID length in ID collision probability calculator.

Custom Alphabet or Length

If you want to change the ID's alphabet or length you can use the internal generate module.

from nanoid import generate

generate('1234567890abcdef', 10) # => "4f9zd13a42"

Non-secure API is also available:

from nanoid import non_secure_generate

non_secure_generate('1234567890abcdef', 10)

Tools

  • ID size calculator to choice smaller ID size depends on your case. nanoid-dictionary with popular alphabets to use with nanoid/generate.
  • nanoid-dictionary with popular alphabets to use.

Other Programming Languages

Changelog

  • v2.0.0
    • Replace ~ to - in default alphabet.
    • Add non-secure fast generator.
    • Reduce default characters from 22 to 21.
  • v0.3.0
    • Fix array out of bound error.

Credits

py-nanoid's People

Contributors

dairaidarkhanov avatar delimitry avatar etrepum avatar paul-yuan-appier avatar puyuan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.