Flask-RESTive extension to work with identifiers.
Project description
# flask-restive-identifiers
Flask-RESTive extension to work with identifiers.
[](https://travis-ci.org/left-join/flask-restive-identifiers)
[](https://coveralls.io/github/left-join/flask-restive-identifiers?branch=master)
[](https://landscape.io/github/left-join/flask-restive-identifiers/master)
[](https://pypi.python.org/pypi/Flask-RESTive-Identifiers)
## Installation
```bash
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:
```python
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:
```python
>>> 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:
```python
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:
```python
>>> schema = ScientistSchema()
>>> data, errors = schema.load({'first_name': 'Albert', 'last_name': 'Einstein'})
>>> data.id
1
>>> data, errors = schema.load({'first_name': 'Nicolaus', 'last_name': 'Copernicus'})
>>> data.id
2
```
Flask-RESTive extension to work with identifiers.
[](https://travis-ci.org/left-join/flask-restive-identifiers)
[](https://coveralls.io/github/left-join/flask-restive-identifiers?branch=master)
[](https://landscape.io/github/left-join/flask-restive-identifiers/master)
[](https://pypi.python.org/pypi/Flask-RESTive-Identifiers)
## Installation
```bash
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:
```python
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:
```python
>>> 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:
```python
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:
```python
>>> schema = ScientistSchema()
>>> data, errors = schema.load({'first_name': 'Albert', 'last_name': 'Einstein'})
>>> data.id
1
>>> data, errors = schema.load({'first_name': 'Nicolaus', 'last_name': 'Copernicus'})
>>> data.id
2
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Flask-RESTive-Identifiers-0.0.3.tar.gz
.
File metadata
- Download URL: Flask-RESTive-Identifiers-0.0.3.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
f8dd11d70327b1f0371c1672eda10d5acb0ce815f5a47deb32a90ac38521d8ad
|
|
MD5 |
13ef06a426c6768a8b4fca78e013c225
|
|
BLAKE2b-256 |
24fba688b769938896374e445a4ceb3e0950ccacf79cf34133eca917b1b726cd
|
File details
Details for the file Flask_RESTive_Identifiers-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: Flask_RESTive_Identifiers-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
ac1ab573c9d37a940bece113e0eb84b1f3785b1b9c161cde6abf9cb87ebeaf89
|
|
MD5 |
3a5b4b86bcb0559828c337e4555430ed
|
|
BLAKE2b-256 |
8fe9a23583336cd3e2ecc79911a14cb9e34fe7f5cbdbc42ee8335b2c1926b958
|