Skip to main content

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:

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)

Uploaded Source

Built Distribution

Flask_Hashids-0.2.1-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page