Skip to main content

Flask-RESTive extension to work with identifiers.

Project description

# flask-restive-identifiers
Flask-RESTive extension to work with identifiers.

[![Build Status](](
[![Coverage Status](](
[![Code Health](](
[![PyPI Version](](

## Installation
pip install flask-restive-identifiers

## How to use

The library based on postgresql sequences, so you should to configure your
application to use postgresql first:
from flask import Flask

app = Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://user:password@localhost:5432/database'

The library provides function generate_id that can be used as is:
>>> from flask_restive_identifiers import generate_id

>>> generate_id(namespace='test')
>>> 1
>>> generate_id(namespace='test')
>>> 2
>>> generate_id(namespace='test')
>>> 3
>>> generate_id(namespace='new_space')
>>> 1

The library provides schema that automatically generates auto-increment id.

The sequence name can be changed with meta attribute identifier_namespace:
from flask_restive import fields
from flask_restive_identifiers import IntegerIDSchema

class ScientistSchema(IntegerIDSchema):
first_name = fields.String(required=True)
last_name = fields.String(required=True)

class Meta(IntegerIDSchema.Meta):
identifier_namespace = 'scientists'


Each loading without id generates new auto-increment id:
>>> schema = ScientistSchema()
>>> data, errors = schema.load({'first_name': 'Albert', 'last_name': 'Einstein'})
>>> data, errors = schema.load({'first_name': 'Nicolaus', 'last_name': 'Copernicus'})

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Flask-RESTive-Identifiers, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size Flask_RESTive_Identifiers-0.0.3-py3-none-any.whl (6.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size Flask-RESTive-Identifiers-0.0.3.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page