{"id":8740,"library":"types-nanoid","title":"Typing Stubs for nanoid","description":"types-nanoid is a PEP 561 type stub package that provides static type annotations for the `nanoid` library. It allows type checkers such as MyPy, Pyright, and PyCharm to perform static analysis and type inference on code that uses `nanoid`, ensuring type safety without impacting runtime behavior. This version aims to provide accurate annotations for `nanoid==2.0.0`. It is actively maintained as part of the `typeshed` project, with updates typically correlating to upstream `nanoid` releases or general typeshed improvements.","status":"active","version":"2.0.0.20260408","language":"python","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","nanoid","type-checking","typeshed"],"install":[{"cmd":"pip install types-nanoid","lang":"bash","label":"Install only type stubs"},{"cmd":"pip install nanoid types-nanoid","lang":"bash","label":"Install runtime and type stubs"}],"dependencies":[{"reason":"Provides runtime implementation for which these stubs offer type hints.","package":"nanoid","optional":false}],"imports":[{"wrong":"from nanoid_stubs import generate","symbol":"generate","correct":"from nanoid_stubs import generate"}],"quickstart":{"code":"import os\nfrom nanoid import generate, non_secure_generate\n\ndef create_ids() -> None:\n    # Generate a cryptographically strong, URL-friendly unique ID\n    secure_id: str = generate()\n    print(f\"Secure ID: {secure_id}\")\n\n    # Generate a non-secure ID (for non-security-critical applications)\n    non_secure_id: str = non_secure_generate(size=10)\n    print(f\"Non-Secure ID (10 chars): {non_secure_id}\")\n\n    # Generate with a custom alphabet and size\n    custom_alphabet_id: str = generate('1234567890abcdef', 8)\n    print(f\"Custom Alphabet ID: {custom_alphabet_id}\")\n\n\nif __name__ == \"__main__\":\n    create_ids()","lang":"python","description":"This quickstart demonstrates how to install both the `nanoid` library and its corresponding type stubs, `types-nanoid`. It then shows how to use `nanoid.generate` for secure IDs and `nanoid.non_secure_generate` for performance-critical, non-security-sensitive cases, all while leveraging the type hints provided by `types-nanoid` for static analysis."},"warnings":[{"fix":"Ensure `nanoid` and `types-nanoid` are installed with compatible versions. For example, if `types-nanoid` is for `nanoid==2.0.0`, install both as `pip install \"nanoid==2.0.0\" \"types-nanoid==2.0.0.*\"`. Consult the `typeshed` repository for specific version compatibility notes.","message":"Type stub versions should ideally align with the major version of the runtime library they type. A mismatch between `types-nanoid` and the installed `nanoid` version can lead to incorrect type-checking results or errors.","severity":"breaking","affected_versions":"All versions of `types-nanoid` when `nanoid` is a different major version."},{"fix":"For Python projects, always install `types-nanoid` explicitly for type checking alongside the `nanoid` runtime library.","message":"There can be confusion with the JavaScript `@types/nanoid` package, which is deprecated because the JS `nanoid` library now includes its own types. In Python, however, `types-nanoid` is still necessary for type checking as the `nanoid` Python package does not typically bundle `py.typed` files for static analysis.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For any security-critical ID generation (e.g., session tokens, API keys), always use `nanoid.generate()`. Reserve `nanoid.non_secure_generate()` only for cases where performance is prioritized over cryptographic strength and security is not a concern (e.g., temporary internal identifiers).","message":"The `nanoid` library offers `non_secure_generate` which uses `random.random` internally. This function is explicitly \"not recommended for generating tokens or secrets\" due to its weaker cryptographic strength compared to `generate()`. Using it in security-sensitive contexts is a footgun.","severity":"gotcha","affected_versions":"All versions of `nanoid` and `types-nanoid`."}],"env_vars":null,"search_vec":"'2.0.0':62 '561':11 'accur':58 'activ':65 'aim':55 'allow':25 'analysi':37 'annot':19,59 'behavior':52 'check':90 'checker':27 'code':42 'correl':76 'ensur':46 'general':82 'impact':50 'improv':84 'infer':40 'librari':23 'maintain':66 'mypi':30 'nanoid':4,7,22,45,61,79,87 'packag':14 'part':68 'pep':10 'perform':35 'project':72 'provid':16,57 'pycharm':33 'pyright':31 'releas':80 'runtim':51 'safeti':48 'static':17,36 'stub':2,13,86 'type':1,6,12,18,26,39,47,85,89 'type-check':88 'types-nanoid':5 'typesh':71,83,91 'typic':75 'updat':74 'upstream':78 'use':44 'version':54 'without':49","created_at":"2026-04-16T17:03:45.534937+00:00","updated_at":"2026-04-16T17:03:45.534937+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nModuleNotFoundError: No module named 'nanoid_stubs'"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.0.0.20260508","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/typeshed-internal/stub_uploader","docs":null,"changelog":"https://github.com/typeshed-internal/stub_uploader/blob/main/data/changelogs/nanoid.md","pypi":"https://pypi.org/project/types-nanoid/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["type-stubs"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}