# chisel
[![PyPI - Status](https://img.shields.io/pypi/status/chisel)](https://pypi.org/project/chisel/)
[![PyPI](https://img.shields.io/pypi/v/chisel)](https://pypi.org/project/chisel/)
[![GitHub](https://img.shields.io/github/license/craigahobbs/chisel)](https://github.com/craigahobbs/chisel/blob/main/LICENSE)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/chisel)](https://pypi.org/project/chisel/)
Chisel is a light-weight Python WSGI application framework built for creating well-documented,
schema-validated JSON web APIs.
## Links
- [API Documentation](https://craigahobbs.github.io/chisel/)
- [Source code](https://github.com/craigahobbs/chisel)
## JSON APIs
Chisel provides the [action](https://craigahobbs.github.io/chisel/action.html#chisel.action)
decorator for easily implementing schema-validated JSON APIs.
~~~ python
@chisel.action(spec='''
# Sum a list of numbers
action sum_numbers
urls
GET
query
# The list of numbers
float[len > 0] numbers
output
# The sum of the numbers
float sum
''')
def sum_numbers(ctx, req):
return {'sum': sum(req['numbers'])}
application = chisel.Application()
application.add_request(sum_numbers)
application.request('GET', '/sum_numbers', query_string='numbers.0=1&numbers.1=2&numbers.2=4')
('200 OK', [('Content-Type', 'application/json')], b'{"sum":7.0}')
~~~
Each action defines an ``action`` definition using
[Schema Markdown](https://craigahobbs.github.io/schema-markdown-js/language/).
The action callback is passed two arguments, a request
[Context](https://craigahobbs.github.io/chisel/app.html#chisel.Context)
and the schema-validated request input dictionary. The input request dictionary is created by
combining the request's URL path parameters, query string parameters, and input JSON content
parameters.
If there is a schema validation error the appropriate error code is automatically returned.
~~~ python
status, _, content_bytes = application.request('GET', '/sum_numbers')
'400 Bad Request'
b'{"error":"InvalidInput","message":"Required member \'numbers\' missing (query string)"}'
~~~
## API Documentation
You can add API documentation to your application by adding the Chisel documentation application
requests from
[create_doc_requests](https://craigahobbs.github.io/chisel/request.html#chisel.create_doc_requests).
~~~ python
application = chisel.Application()
application.add_requests(chisel.create_doc_requests())
~~~
By default the documentation application is hosted at "/doc/". An example of of Chisel's documentation output is
available [here](https://craigahobbs.github.io/chisel/example/#var.vName='chisel_doc_request').
## Development
This package is developed using [python-build](https://github.com/craigahobbs/python-build#readme).
It was started using [python-template](https://github.com/craigahobbs/python-template#readme) as follows:
~~~ sh
template-specialize python-template/template/ chisel/ -k package chisel -k name 'Craig A. Hobbs' -k email 'craigahobbs@gmail.com' -k github 'craigahobbs' -k nomain 1
~~~
Raw data
{
"_id": null,
"home_page": "https://github.com/craigahobbs/chisel",
"name": "chisel",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "api, json, framework, schema, wsgi",
"author": "Craig A. Hobbs",
"author_email": "craigahobbs@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/c1/88/9f41df02e00a808a19c7fabc8188349c8fea7799774e2c0d6a86a97cb0c9/chisel-1.2.7.tar.gz",
"platform": null,
"description": "# chisel\n\n[![PyPI - Status](https://img.shields.io/pypi/status/chisel)](https://pypi.org/project/chisel/)\n[![PyPI](https://img.shields.io/pypi/v/chisel)](https://pypi.org/project/chisel/)\n[![GitHub](https://img.shields.io/github/license/craigahobbs/chisel)](https://github.com/craigahobbs/chisel/blob/main/LICENSE)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/chisel)](https://pypi.org/project/chisel/)\n\nChisel is a light-weight Python WSGI application framework built for creating well-documented,\nschema-validated JSON web APIs.\n\n\n## Links\n\n- [API Documentation](https://craigahobbs.github.io/chisel/)\n- [Source code](https://github.com/craigahobbs/chisel)\n\n\n## JSON APIs\n\nChisel provides the [action](https://craigahobbs.github.io/chisel/action.html#chisel.action)\ndecorator for easily implementing schema-validated JSON APIs.\n\n~~~ python\n@chisel.action(spec='''\n# Sum a list of numbers\naction sum_numbers\n urls\n GET\n\n query\n # The list of numbers\n float[len > 0] numbers\n\n output\n # The sum of the numbers\n float sum\n''')\ndef sum_numbers(ctx, req):\n return {'sum': sum(req['numbers'])}\n\napplication = chisel.Application()\napplication.add_request(sum_numbers)\napplication.request('GET', '/sum_numbers', query_string='numbers.0=1&numbers.1=2&numbers.2=4')\n\n('200 OK', [('Content-Type', 'application/json')], b'{\"sum\":7.0}')\n~~~\n\nEach action defines an ``action`` definition using\n[Schema Markdown](https://craigahobbs.github.io/schema-markdown-js/language/).\nThe action callback is passed two arguments, a request\n[Context](https://craigahobbs.github.io/chisel/app.html#chisel.Context)\nand the schema-validated request input dictionary. The input request dictionary is created by\ncombining the request's URL path parameters, query string parameters, and input JSON content\nparameters.\n\nIf there is a schema validation error the appropriate error code is automatically returned.\n\n~~~ python\nstatus, _, content_bytes = application.request('GET', '/sum_numbers')\n\n'400 Bad Request'\nb'{\"error\":\"InvalidInput\",\"message\":\"Required member \\'numbers\\' missing (query string)\"}'\n~~~\n\n\n## API Documentation\n\nYou can add API documentation to your application by adding the Chisel documentation application\nrequests from\n[create_doc_requests](https://craigahobbs.github.io/chisel/request.html#chisel.create_doc_requests).\n\n~~~ python\napplication = chisel.Application()\napplication.add_requests(chisel.create_doc_requests())\n~~~\n\nBy default the documentation application is hosted at \"/doc/\". An example of of Chisel's documentation output is\navailable [here](https://craigahobbs.github.io/chisel/example/#var.vName='chisel_doc_request').\n\n\n## Development\n\nThis package is developed using [python-build](https://github.com/craigahobbs/python-build#readme).\nIt was started using [python-template](https://github.com/craigahobbs/python-template#readme) as follows:\n\n~~~ sh\ntemplate-specialize python-template/template/ chisel/ -k package chisel -k name 'Craig A. Hobbs' -k email 'craigahobbs@gmail.com' -k github 'craigahobbs' -k nomain 1\n~~~\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Lightweight WSGI application framework, schema-validated JSON APIs, and API documentation",
"version": "1.2.7",
"project_urls": {
"Homepage": "https://github.com/craigahobbs/chisel"
},
"split_keywords": [
"api",
" json",
" framework",
" schema",
" wsgi"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c2773da1f3ce89ed422672c0606bb0e0a70604717bf70ce28fd78969324faac9",
"md5": "58ce0ba305b4bff8777c5fef158854c8",
"sha256": "e36bc230ecadb134941623ab986e449a6719a623f9ee8c6cfae2f6f336fc67bc"
},
"downloads": -1,
"filename": "chisel-1.2.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "58ce0ba305b4bff8777c5fef158854c8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 18006,
"upload_time": "2024-04-05T18:10:30",
"upload_time_iso_8601": "2024-04-05T18:10:30.487978Z",
"url": "https://files.pythonhosted.org/packages/c2/77/3da1f3ce89ed422672c0606bb0e0a70604717bf70ce28fd78969324faac9/chisel-1.2.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c1889f41df02e00a808a19c7fabc8188349c8fea7799774e2c0d6a86a97cb0c9",
"md5": "8ca5d351cadc353db4bbd018e8a9879f",
"sha256": "ba2701d94e30e28cd5c533ec2dfab902c1188899d1fa7926c21621e5a0073f3a"
},
"downloads": -1,
"filename": "chisel-1.2.7.tar.gz",
"has_sig": false,
"md5_digest": "8ca5d351cadc353db4bbd018e8a9879f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 16708,
"upload_time": "2024-04-05T18:10:33",
"upload_time_iso_8601": "2024-04-05T18:10:33.067577Z",
"url": "https://files.pythonhosted.org/packages/c1/88/9f41df02e00a808a19c7fabc8188349c8fea7799774e2c0d6a86a97cb0c9/chisel-1.2.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-05 18:10:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "craigahobbs",
"github_project": "chisel",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "chisel"
}