Skip to content
A unique string ID generator for Clojure and ClojureScript
Branch: master
Clone or download
Latest commit 3a3085c Oct 10, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Update Circle CI config: bump lein version to 2.8.1 Jul 6, 2018
src/nano_id Replace ~ with - in default alphabet Oct 9, 2019
test/nano_id Replace ~ with - in default alphabet Oct 9, 2019
.gitignore Bump version to 0.10.0 Oct 9, 2019
LICENSE Init Jun 26, 2018 Update readme Oct 10, 2019
package.json Bump version to 0.10.0 Oct 9, 2019
project.clj Bump version to 0.10.0 Oct 9, 2019


A tiny, secure, URL-friendly unique string ID generator for both Clojure and ClojureScript.

Clojars Project cljdoc badge CircleCI


nano-id uses SecureRandom (Clojure) and crypto (ClojureScript) to generate cryptographically strong random IDs with a proper distribution of characters.


nano-id generates compact IDs with just 21 characters. By using a larger alphabet than UUID, nano-id can generate a greater number of unique IDs, when compared to UUID, with fewer characters (21 versus 36).


nano-id uses URL-friendly characters [A-Za-z0-9_-]. Perfect for unique identifiers in web applications.



Add to your project.clj: [nano-id "0.10.0"].

The default implementation uses 64-character alphabet and generates 21-character IDs.

user=> (require '[nano-id.core :refer [nano-id]])

user=> (nano-id)

But you can pass the size

user=> (nano-id 10)

Custom alphabet or random number generator

Also you can provide your own alphabet as follow

user=> (require '[nano-id.custom :refer [generate]])

user=> (def my-nano-id (generate "abc"))

user=> (my-nano-id 10)

Or your custom random number generator, for example

(let [alphabet "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
      time-gen (fn [n] (take n (iterate #(unsigned-bit-shift-right % 6)
                                        (quot (System/currentTimeMillis) 1000))))
      time-id  (generate alphabet time-gen)]
  (time-id 6))

This encodes current time using a lexicographical alphabet.


Copyright and license

Code copyright 2018 nano-id authors and Andrey Sitnik. Code released under the MIT License.

Based on the original nanoid for JavaScript by Andrey Sitnik.

You can’t perform that action at this time.