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
from flask import abort, Flask, render_template, url_for
from flask_hashids import HashidMixin, Hashids
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
# The SECRET_KEY is used as a salt, so don't forget to set this in production
app.config['SECRET_KEY'] = 'secret!'
db = SQLAlchemy(app)
hashids = Hashids(app)
class User(HashidMixin, db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), nullable=False)
@app.route('/users')
def users():
hashid_users = [
{
'id': user.hashid, # hashid property from HashidMixin
'name': user.name,
'url': url_for('user', user_id=user.id) # Int id for url generation
} for user in User.query.all()
]
return render_template('users.html', users=hashid_users)
@app.route('/users/<hashid:user_id>')
def user(user_id):
# The HashidConverter decodes the given hashid to an int
user = User.query.get_or_404(user_id):
return render_template('user.html', user=user)
if __name__ == '__main__':
app.run()
Ressources
Metadata
Release files for Flask-Hashids 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| Flask-Hashids-0.2.0.tar.gz | 3.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Flask_Hashids-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.9 kB
Release files / Flask-Hashids-0.2.0.tar.gz
| Download URL | Flask-Hashids-0.2.0.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e28116fec5166c5eb882252f31aad3c0bf88666e3939452c966ec00b50f75c2b
|
|
BLAKE2b-256 checksum How to use checksums |
601d3d8b59f2aec11781071191deddebeb03edcd9e99850aa63096e10f994708
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.7
|
Release files / Flask_Hashids-0.2.0-py3-none-any.whl
| Download URL | Flask_Hashids-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f940be5ffb8d0fffb69777c863130bb8b1d5d0bab803822373d1ad9a8b96614
|
|
BLAKE2b-256 checksum How to use checksums |
95127bd8acaad6573fb9b499557925f04820fcbf5065c1822844e5164fe28b2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.7
|
Security for Flask-Hashids 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.