METADATA 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. Metadata-Version: 2.0
  2. Name: hashids
  3. Version: 1.2.0
  4. Summary: Python implementation of hashids (http://www.hashids.org).Compatible with python 2.6-3.
  5. Home-page: https://github.com/davidaurelio/hashids-python
  6. Author: David Aurelio
  7. Author-email: dev@david-aurelio.com
  8. License: MIT License
  9. Platform: UNKNOWN
  10. Classifier: Programming Language :: Python :: 2
  11. Classifier: Programming Language :: Python :: 2.6
  12. Classifier: Programming Language :: Python :: 2.7
  13. Classifier: Programming Language :: Python :: 3
  14. Classifier: Programming Language :: Python :: 3.2
  15. Classifier: Programming Language :: Python :: 3.3
  16. Classifier: Programming Language :: Python :: 3.4
  17. Classifier: Programming Language :: Python :: 3.5
  18. Classifier: Programming Language :: Python :: 3.6
  19. ========================
  20. hashids for Python 2.6–3
  21. ========================
  22. A python port of the JavaScript *hashids* implementation. It generates YouTube-like hashes from one or many numbers. Use hashids when you do not want to expose your database ids to the user. Website: http://www.hashids.org/
  23. Compatibility
  24. =============
  25. hashids is tested with python 2.6, 2.7, 3.2, 3.3 and 3.4. PyPy and PyPy 3 work as well.
  26. .. image:: https://travis-ci.org/davidaurelio/hashids-python.svg?branch=master
  27. :target: https://travis-ci.org/davidaurelio/hashids-python
  28. Compatibility with the JavaScript implementation
  29. ------------------------------------------------
  30. ================== ==============
  31. hashids/JavaScript hashids/Python
  32. ------------------ --------------
  33. v0.1.x v0.8.x
  34. v0.3.x and v1.0.x v1.0.2+
  35. ================== ==============
  36. The JavaScript implementation produces different hashes in versions 0.1.x and 0.3.x. For compatibility with the older 0.1.x version install hashids 0.8.4 from pip, otherwise the newest hashids.
  37. Installation
  38. ============
  39. Install the module from PyPI, e. g. with pip:
  40. .. code:: bash
  41. pip install hashids
  42. pip install hashids==0.8.4 # for compatibility with hashids.js 0.1.x
  43. Run the tests
  44. =============
  45. The tests are written with `pytest <http://pytest.org/latest/>`_. The pytest module has to be installed.
  46. .. code:: bash
  47. python -m pytest
  48. Usage
  49. =====
  50. Import the constructor from the ``hashids`` module:
  51. .. code:: python
  52. from hashids import Hashids
  53. hashids = Hashids()
  54. Basic Usage
  55. -----------
  56. Encode a single integer:
  57. .. code:: python
  58. hashid = hashids.encode(123) # 'Mj3'
  59. Decode a hash:
  60. .. code:: python
  61. ints = hashids.decode('xoz') # (456,)
  62. To encode several integers, pass them all at once:
  63. .. code:: python
  64. hashid = hashids.encode(123, 456, 789) # 'El3fkRIo3'
  65. Decoding is done the same way:
  66. .. code:: python
  67. ints = hashids.decode('1B8UvJfXm') # (517, 729, 185)
  68. Using A Custom Salt
  69. -------------------
  70. Hashids supports salting hashes by accepting a salt value. If you don’t want others to decode your hashes, provide a unique string to the constructor.
  71. .. code:: python
  72. hashids = Hashids(salt='this is my salt 1')
  73. hashid = hashids.encode(123) # 'nVB'
  74. The generated hash changes whenever the salt is changed:
  75. .. code:: python
  76. hashids = Hashids(salt='this is my salt 2')
  77. hashid = hashids.encode(123) # 'ojK'
  78. A salt string between 6 and 32 characters provides decent randomization.
  79. Controlling Hash Length
  80. -----------------------
  81. By default, hashes are going to be the shortest possible. One reason you might want to increase the hash length is to obfuscate how large the integer behind the hash is.
  82. This is done by passing the minimum hash length to the constructor. Hashes are padded with extra characters to make them seem longer.
  83. .. code:: python
  84. hashids = Hashids(min_length=16)
  85. hashid = hashids.encode(1) # '4q2VolejRejNmGQB'
  86. Using A Custom Alphabet
  87. -----------------------
  88. It’s possible to set a custom alphabet for your hashes. The default alphabet is ``'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'``.
  89. To have only lowercase letters in your hashes, pass in the following custom alphabet:
  90. .. code:: python
  91. hashids = Hashids(alphabet='abcdefghijklmnopqrstuvwxyz')
  92. hashid = hashids.encode(123456789) # 'kekmyzyk'
  93. A custom alphabet must contain at least 16 characters.
  94. Randomness
  95. ==========
  96. The primary purpose of hashids is to obfuscate ids. It's not meant or tested to be used for security purposes or compression. Having said that, this algorithm does try to make these hashes unguessable and unpredictable:
  97. Repeating numbers
  98. -----------------
  99. There are no repeating patterns that might show that there are 4 identical numbers in the hash:
  100. .. code:: python
  101. hashids = Hashids("this is my salt")
  102. hashids.encode(5, 5, 5, 5) # '1Wc8cwcE'
  103. The same is valid for incremented numbers:
  104. .. code:: python
  105. hashids.encode(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) # 'kRHnurhptKcjIDTWC3sx'
  106. hashids.encode(1) # 'NV'
  107. hashids.encode(2) # '6m'
  108. hashids.encode(3) # 'yD'
  109. hashids.encode(4) # '2l'
  110. hashids.encode(5) # 'rD'
  111. Curses! #$%@
  112. ============
  113. This code was written with the intent of placing generated hashes in visible places – like the URL. Which makes it unfortunate if generated hashes accidentally formed a bad word.
  114. Therefore, the algorithm tries to avoid generating most common English curse words by never placing the following letters next to each other: **c, C, s, S, f, F, h, H, u, U, i, I, t, T.**
  115. License
  116. =======
  117. MIT license, see the LICENSE file. You can use hashids in open source projects and commercial products.