Document APIs with CoreAPI.
Project description
coreapidocs [![travis][travis-image]][travis-url] [![pypi][pypi-image]][pypi-url]
===
Document APIs with CoreAPI.
### Prerequisites
- Python (2.7, 3.3, 3.4, 3.5)
- Core API ([Read More](http://www.coreapi.org/))
### Installation
You can install `coreapidocs` through pypi.
pip install coreapidocs
### Usage
You will have to pass a `.json` document to initialize the docs.
```python
from coreapidocs.docs import Docs
try:
schema = open(filename, 'rb').read()
docs = Docs(schema)
except (IOError, OSError):
abort(400, {"msg": "No such file or directory - %s" % filename})
```
Then you can simply pass the `docs` variable to your template (ie. Flask):
```python
return render_template('home.html', docs=docs.get_docs())
```
For more information view the source of [example.py](coreapidocs/example.py).
### Development
Create the virtualenv and install the requirements.
virtualenv env
source env/bin/activate
pip install -r requirements.txt
You will need to pass an argument ie. `document.json`.
python coreapidocs/example.py document.json
# Then go to: http://127.0.0.1:5000/
### Usage
Below you can find an example Flask application. Using `jinja2` you can pass the `coreapidocs` template to your view.
```python
import sys
import jinja2
from flask import Flask, abort, render_template
from coreapidocs.docs import Docs
app = Flask(__name__)
@app.route('/')
def docs():
"""
Generate the coreapidocs and serve them to roor.
Accepts one parameter with a filename (ie. document.json)
"""
if len(sys.argv) != 2:
abort(400, {"msg": "Missing file parameter ie. document.json"})
filename = sys.argv[-1]
try:
schema = open(filename, 'rb').read()
docs = Docs(schema)
except (IOError, OSError):
abort(400, {"msg": "No such file or directory - %s" % filename})
templates_loader = jinja2.PackageLoader('coreapidocs', 'templates')
template_env = jinja2.Environment(loader=templates_loader)
template = template_env.get_template('docs.html')
# FIXME: Figure out how to pas static files
return render_template(template, docs=docs.get_docs())
@app.route('/<path:path>')
def static_proxy(path):
"""
Serve static files.
"send_static_file" will guess the correct MIME type
"""
return app.send_static_file(path)
if __name__ == '__main__':
app.debug = True
app.run()
```
### Tests
In order to run the tests you will have to run:
python runtests.py
[travis-image]: https://travis-ci.org/ekonstantinidis/coreapidocs.svg
[travis-url]: https://travis-ci.org/ekonstantinidis/coreapidocs
[pypi-image]: https://badge.fury.io/py/coreapidocs.svg
[pypi-url]: https://pypi.python.org/pypi/coreapidocs/
===
Document APIs with CoreAPI.
### Prerequisites
- Python (2.7, 3.3, 3.4, 3.5)
- Core API ([Read More](http://www.coreapi.org/))
### Installation
You can install `coreapidocs` through pypi.
pip install coreapidocs
### Usage
You will have to pass a `.json` document to initialize the docs.
```python
from coreapidocs.docs import Docs
try:
schema = open(filename, 'rb').read()
docs = Docs(schema)
except (IOError, OSError):
abort(400, {"msg": "No such file or directory - %s" % filename})
```
Then you can simply pass the `docs` variable to your template (ie. Flask):
```python
return render_template('home.html', docs=docs.get_docs())
```
For more information view the source of [example.py](coreapidocs/example.py).
### Development
Create the virtualenv and install the requirements.
virtualenv env
source env/bin/activate
pip install -r requirements.txt
You will need to pass an argument ie. `document.json`.
python coreapidocs/example.py document.json
# Then go to: http://127.0.0.1:5000/
### Usage
Below you can find an example Flask application. Using `jinja2` you can pass the `coreapidocs` template to your view.
```python
import sys
import jinja2
from flask import Flask, abort, render_template
from coreapidocs.docs import Docs
app = Flask(__name__)
@app.route('/')
def docs():
"""
Generate the coreapidocs and serve them to roor.
Accepts one parameter with a filename (ie. document.json)
"""
if len(sys.argv) != 2:
abort(400, {"msg": "Missing file parameter ie. document.json"})
filename = sys.argv[-1]
try:
schema = open(filename, 'rb').read()
docs = Docs(schema)
except (IOError, OSError):
abort(400, {"msg": "No such file or directory - %s" % filename})
templates_loader = jinja2.PackageLoader('coreapidocs', 'templates')
template_env = jinja2.Environment(loader=templates_loader)
template = template_env.get_template('docs.html')
# FIXME: Figure out how to pas static files
return render_template(template, docs=docs.get_docs())
@app.route('/<path:path>')
def static_proxy(path):
"""
Serve static files.
"send_static_file" will guess the correct MIME type
"""
return app.send_static_file(path)
if __name__ == '__main__':
app.debug = True
app.run()
```
### Tests
In order to run the tests you will have to run:
python runtests.py
[travis-image]: https://travis-ci.org/ekonstantinidis/coreapidocs.svg
[travis-url]: https://travis-ci.org/ekonstantinidis/coreapidocs
[pypi-image]: https://badge.fury.io/py/coreapidocs.svg
[pypi-url]: https://pypi.python.org/pypi/coreapidocs/
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
coreapidocs-0.0.2.tar.gz
(6.4 kB
view details)
File details
Details for the file coreapidocs-0.0.2.tar.gz
.
File metadata
- Download URL: coreapidocs-0.0.2.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a9c45f7852a3dda5efde52be439f0340f286439d874b7d133e0c973c76b1906 |
|
MD5 | 85770f5893d0604509d566e9161b7d08 |
|
BLAKE2b-256 | 0960b6ae0615b6eeb2b45c170ac5fcc4298141fd5685e517785ca682983a2c2d |