Flask decorator to output RDF using content negotiation
Project description
Flask\_rdf
==========
A Flask decorator to output RDF using content negotiation.
Apply the @flask\_rdf decorator to a view function and return an rdflib Graph object. Flask\_rdf will automatically format it into an RDF output format, depending on what the request's Accept header says. If the view function return something besides an rdflib graph, it will be passed through without modification.
API
---
- `add_format` - registers a new (mimetype, serialize\_format) pair, in case you've added some extra rdflib plugins
- `decide_format` - Given an Accept header, return a (mimetype, format) tuple to be used
- `flask_rdf` - Decorator to handle returning an rdflib Graph object and formatting it for the client
Example
-------
```python
#!/usr/bin/env python
from rdflib import Graph, BNode, Literal, URIRef
from rdflib.namespace import FOAF
from flask import Flask
from flask_rdf import flask_rdf
import random
app = Flask(__name__)
@app.route('/')
@app.route('/<path:path>')
@flask_rdf
def random_age(path=''):
graph = Graph('IOMemory', BNode())
graph.add((URIRef(path), FOAF.age, Literal(random.randint(20, 50))))
return graph
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
```
[![Build Status](https://travis-ci.org/hufman/flask_rdf.svg?branch=master)](https://travis-ci.org/hufman/flask_rdf)
==========
A Flask decorator to output RDF using content negotiation.
Apply the @flask\_rdf decorator to a view function and return an rdflib Graph object. Flask\_rdf will automatically format it into an RDF output format, depending on what the request's Accept header says. If the view function return something besides an rdflib graph, it will be passed through without modification.
API
---
- `add_format` - registers a new (mimetype, serialize\_format) pair, in case you've added some extra rdflib plugins
- `decide_format` - Given an Accept header, return a (mimetype, format) tuple to be used
- `flask_rdf` - Decorator to handle returning an rdflib Graph object and formatting it for the client
Example
-------
```python
#!/usr/bin/env python
from rdflib import Graph, BNode, Literal, URIRef
from rdflib.namespace import FOAF
from flask import Flask
from flask_rdf import flask_rdf
import random
app = Flask(__name__)
@app.route('/')
@app.route('/<path:path>')
@flask_rdf
def random_age(path=''):
graph = Graph('IOMemory', BNode())
graph.add((URIRef(path), FOAF.age, Literal(random.randint(20, 50))))
return graph
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
```
[![Build Status](https://travis-ci.org/hufman/flask_rdf.svg?branch=master)](https://travis-ci.org/hufman/flask_rdf)
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_rdf-0.1.5.tar.gz
(3.0 kB
view hashes)
Built Distributions
Close
Hashes for flask_rdf-0.1.5.linux-i686.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e026ba15b97fc83aff1d80f4309f85b9c9ce59de4ec76b8134ac41a74efaf06 |
|
MD5 | 81705322d52549bcf28bd61e9ca87767 |
|
BLAKE2b-256 | 12c5b4408bbf2f306f12f5ea539039f47b104ee383a69d7f350fe59ad695950f |
Close
Hashes for flask_rdf-0.1.5-py27-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e43825d10a96d10395c95bc70409fcce30ed312857e3a47f223757850943cd5 |
|
MD5 | 616c7bd50a5d2d0e40fb88667411584f |
|
BLAKE2b-256 | 34c2a39458baf61f3faef446a53c9df4374211ba204d4eff223ed52fd27a8cdb |