# 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/60/6a/4fe1e58ee7ef629f4edc579e34440bcc2601f021c6895911ea70861974d1/chisel-1.3.6.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.3.6",
"project_urls": {
"Homepage": "https://github.com/craigahobbs/chisel"
},
"split_keywords": [
"api",
" json",
" framework",
" schema",
" wsgi"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "bf42e19bf7ba452a9b16b44e18cfa778ff4abf87c9c572dd87a95c54d51670d1",
"md5": "36a3f5bf5870290a254fc21b3adc5a04",
"sha256": "14de58af8218bfd896957fa1fac25413f71d97012563cafb9700199843151870"
},
"downloads": -1,
"filename": "chisel-1.3.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "36a3f5bf5870290a254fc21b3adc5a04",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 19647,
"upload_time": "2024-10-02T17:24:48",
"upload_time_iso_8601": "2024-10-02T17:24:48.060666Z",
"url": "https://files.pythonhosted.org/packages/bf/42/e19bf7ba452a9b16b44e18cfa778ff4abf87c9c572dd87a95c54d51670d1/chisel-1.3.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "606a4fe1e58ee7ef629f4edc579e34440bcc2601f021c6895911ea70861974d1",
"md5": "488d94e67c4531dda437b46de1852acb",
"sha256": "5da483b319beeaa53a919b3eef48287f1eaff1b8033afb1e12c2c5e4523df3b7"
},
"downloads": -1,
"filename": "chisel-1.3.6.tar.gz",
"has_sig": false,
"md5_digest": "488d94e67c4531dda437b46de1852acb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17717,
"upload_time": "2024-10-02T17:24:49",
"upload_time_iso_8601": "2024-10-02T17:24:49.613040Z",
"url": "https://files.pythonhosted.org/packages/60/6a/4fe1e58ee7ef629f4edc579e34440bcc2601f021c6895911ea70861974d1/chisel-1.3.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-02 17:24:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "craigahobbs",
"github_project": "chisel",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "chisel"
}