Hashids integration for Flask applications.
Project description
Flask-Hashids
Hashids integration for Flask applications, it is based on the Hashid package available on PyPi. With this extension you can conveniently use integer ids for your application logic or database tables and hash them before exposing it in URLs or JSON data.
Installation
The latest stable version is available on PyPI. Either add Flask-Hashids
to your requirements.txt
file or install with pip:
pip install Flask-Hashids
Configuration
Flask-Hashids is configured through the standard Flask config API. These are the available options:
- HASHIDS_ALPHABET: Read more about that in Hashids documentation
- HASHIDS_MIN_LENGTH: Read more about that in Hashids documentation
- SECRET_KEY: Used as the salt, read more in Hashids documentation
Examples
You can find detailed examples on how to use Flask-Hashids in the examples directory.
HashidConverter
@app.route('/resources/<hashid:resource_id')
def get_resource(resource_id: int):
# The HashidConverter decodes the given hashid to an int
print(isinstance(resource_id, int)) # True
# The HashidConverter encodes the given id to a hashid in the URL
url_for('get_resource', resource_id=resource_id) # '/resources/Mj3'
Manual usage
def some_function(resource_id: int):
hashid = current_app.extensions['hashids'].encode(resource_id) # 'Mj3'
decoded_id = current_app.extensions['hashids'].decode(hashid) # 123
Resources
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Flask-Hashids-0.2.1.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for Flask_Hashids-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27d49ca8dbd7a5e74cca72f340dac7b18411da30c2815aa830e7416ace453573 |
|
MD5 | 2d678ff7bfe62c1d9a297d5a65219f8c |
|
BLAKE2b-256 | 2b4f655f57920bd53c28082ce7dc806b58762715cc3f172f8256bc26d066550a |