# flask-apiblueprint **Repository Path**: mirrors_enthought/flask-apiblueprint ## Basic Information - **Project Name**: flask-apiblueprint - **Description**: Default Repo description from terraform module - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-08 - **Last Updated**: 2025-10-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Flask-APIBlueprint ================== What is Flask-APIBlueprint? ------------------------- Flask-APIBlueprint is a Flask micro-framework extension which adds support for route inheritance for Blueprints. If you're building an API with Blueprints in Flask, you don't have to redeclare the routes if using the `APIBlueprint` class. You can also override routes as you version your API and remap endpoints. #### What do I need? Flask. It will automatically be installed if you install the extension via pip: ``` $ pip install flask-apiblueprint ``` #### Where are the tests? To run the tests use the `test_apiblueprint.py` file: ``` $ python test_apiblueprint.py ``` #### How do I implement this? ##### Inheritance Use the `inherit_from` keyword argument in the `APIBlueprint` constructor to copy routes over from another `APIBlueprint`. ``` api_v2 = APIBlueprint( 'api_v2', __name__, subdomain='', url_prefix='/api/v2', inherit_from=api_v1 ) ``` ##### Override routes To override copied routes, just redeclare them. ``` @api_v1.route('/user//') def username(user_id): username = User.query.get(user_id).username return jsonify(username=username) @api_v2.route('/user//') def user_info(user_id): username = User.query.get(user_id).username firstname = User.query.get(user_id).firstname return jsonify(data=dict(username=username, firstname=firstname)) ``` ##### Remap endpoints Use the `remapping` keyword argument in the constructor to change the endpoints of inherited routes. ``` remapping = {'/users/list/': '/users/'} api_v2 = APIBlueprint( 'api_v2', __name__, subdomain='', url_prefix='/api/v2', inherit_from=api_v1, remapping=remapping ) ``` See the [docs](http://flask-apiblueprint.readthedocs.org/en/latest/) for more details or run the `app.py` file to see how the [sample_api](sample_api) is implemented. ``` $ python app.py ```