ju


Nameju JSON
Version 0.1.16 PyPI version JSON
download
home_pageNone
SummaryJSON schema Utils
upload_time2024-12-20 00:21:17
maintainerNone
docs_urlNone
authorOtoSense
requires_pythonNone
licenseapache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ju

JSON schema Utils

To install:	```pip install ju```

[Documentation](https://i2mint.github.io/ju/)


# Examples

## JSON Schema

You have tools to extract JSON schema information from python objects, as well as 
to create python objects from them.


    >>> from ju import signature_to_json_schema, json_schema_to_signature
    >>>
    >>>
    >>> def earth(north: str, south: bool, east: int = 1, west: float = 2.0):
    ...     """Earth docs"""
    ...     return f'{north=}, {south=}, {east=}, {west=}'
    ...
    >>> schema = signature_to_json_schema(earth)
    >>> assert schema == {
    ...     'description': 'Earth docs',
    ...     'title': 'earth',
    ...     'type': 'object',
    ...     'properties': {
    ...         'north': {'type': 'string'},
    ...         'south': {'type': 'boolean'},
    ...         'east': {'type': 'integer', 'default': 1},
    ...         'west': {'type': 'number', 'default': 2.0},
    ...     },
    ...     'required': ['north', 'south'],
    ... }
    >>>
    >>> sig = json_schema_to_signature(schema)
    >>> sig
    <Sig (north: str, south: bool, east: int = 1, west: float = 2.0)>
    >>> sig.name
    'earth'
    >>> sig.docs
    'Earth docs'


## React JSON Schema Form (rjsf)

You can get a [react-jsonschema-form (rjsf)](https://github.com/rjsf-team/react-jsonschema-form)
specification 
(see the [rjsf playground](https://rjsf-team.github.io/react-jsonschema-form/))
from a python function.


    >>> def foo(
        ...     a_bool: bool,
        ...     a_float=3.14,
        ...     an_int=2,
        ...     a_str: str = 'hello',
        ...     something_else=None
        ... ):
        ...     '''A Foo function'''
        >>>
        >>> form_spec = func_to_form_spec(foo)
        >>> assert form_spec == {
        ...     'rjsf': {
        ...         'schema': {
        ...             'title': 'foo',
        ...             'type': 'object',
        ...             'properties': {
        ...                 'a_bool': {'type': 'boolean'},
        ...                 'a_float': {'type': 'number', 'default': 3.14},
        ...                 'an_int': {'type': 'integer', 'default': 2},
        ...                 'a_str': {'type': 'string', 'default': 'hello'},
        ...                 'something_else': {'type': 'string', 'default': None}
        ...             },
        ...             'required': ['a_bool'],
        ...             'description': 'A Foo function'
        ...         },
        ...         'uiSchema': {
        ...             'ui:submitButtonOptions': {
        ...                 'submitText': 'Run'
        ...             },
        ...             'a_bool': {'ui:autofocus': True}
        ...         },
        ...         'liveValidate': False,
        ...         'disabled': False,
        ...         'readonly': False,
        ...         'omitExtraData': False,
        ...         'liveOmit': False,
        ...         'noValidate': False,
        ...         'noHtml5Validate': False,
        ...         'focusOnFirstError': False,
        ...         'showErrorList': 'top'
        ...     }
        ... }
        

## OpenAPI Routes

Represents a collection of routes in an OpenAPI specification.

Each instance of this class contains a list of `Route` objects, which can be accessed and manipulated as needed.


    >>> from yaml import safe_load
    >>> spec_yaml = '''
    ... openapi: 3.0.3
    ... paths:
    ...   /items:
    ...     get:
    ...       summary: List items
    ...       responses:
    ...         '200':
    ...           description: An array of items
    ...     post:
    ...       summary: Create item
    ...       responses:
    ...         '201':
    ...           description: Item created
    ... '''
    >>> spec = safe_load(spec_yaml)
    >>> routes = Routes(spec)
    >>> len(routes)
    2
    >>> list(routes)
    [('get', '/items'), ('post', '/items')]
    >>> r = routes['get', '/items']
    >>> r
    Route(method='get', endpoint='/items')
    >>> r.method_data
    {'summary': 'List items', 'responses': {'200': {'description': 'An array of items'}}}


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ju",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "OtoSense",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/1f/b1/a877daa67052685f1b9c69e4118085b6d96b6def31c8975d665fe59c4ba4/ju-0.1.16.tar.gz",
    "platform": null,
    "description": "# ju\n\nJSON schema Utils\n\nTo install:\t```pip install ju```\n\n[Documentation](https://i2mint.github.io/ju/)\n\n\n# Examples\n\n## JSON Schema\n\nYou have tools to extract JSON schema information from python objects, as well as \nto create python objects from them.\n\n\n    >>> from ju import signature_to_json_schema, json_schema_to_signature\n    >>>\n    >>>\n    >>> def earth(north: str, south: bool, east: int = 1, west: float = 2.0):\n    ...     \"\"\"Earth docs\"\"\"\n    ...     return f'{north=}, {south=}, {east=}, {west=}'\n    ...\n    >>> schema = signature_to_json_schema(earth)\n    >>> assert schema == {\n    ...     'description': 'Earth docs',\n    ...     'title': 'earth',\n    ...     'type': 'object',\n    ...     'properties': {\n    ...         'north': {'type': 'string'},\n    ...         'south': {'type': 'boolean'},\n    ...         'east': {'type': 'integer', 'default': 1},\n    ...         'west': {'type': 'number', 'default': 2.0},\n    ...     },\n    ...     'required': ['north', 'south'],\n    ... }\n    >>>\n    >>> sig = json_schema_to_signature(schema)\n    >>> sig\n    <Sig (north: str, south: bool, east: int = 1, west: float = 2.0)>\n    >>> sig.name\n    'earth'\n    >>> sig.docs\n    'Earth docs'\n\n\n## React JSON Schema Form (rjsf)\n\nYou can get a [react-jsonschema-form (rjsf)](https://github.com/rjsf-team/react-jsonschema-form)\nspecification \n(see the [rjsf playground](https://rjsf-team.github.io/react-jsonschema-form/))\nfrom a python function.\n\n\n    >>> def foo(\n        ...     a_bool: bool,\n        ...     a_float=3.14,\n        ...     an_int=2,\n        ...     a_str: str = 'hello',\n        ...     something_else=None\n        ... ):\n        ...     '''A Foo function'''\n        >>>\n        >>> form_spec = func_to_form_spec(foo)\n        >>> assert form_spec == {\n        ...     'rjsf': {\n        ...         'schema': {\n        ...             'title': 'foo',\n        ...             'type': 'object',\n        ...             'properties': {\n        ...                 'a_bool': {'type': 'boolean'},\n        ...                 'a_float': {'type': 'number', 'default': 3.14},\n        ...                 'an_int': {'type': 'integer', 'default': 2},\n        ...                 'a_str': {'type': 'string', 'default': 'hello'},\n        ...                 'something_else': {'type': 'string', 'default': None}\n        ...             },\n        ...             'required': ['a_bool'],\n        ...             'description': 'A Foo function'\n        ...         },\n        ...         'uiSchema': {\n        ...             'ui:submitButtonOptions': {\n        ...                 'submitText': 'Run'\n        ...             },\n        ...             'a_bool': {'ui:autofocus': True}\n        ...         },\n        ...         'liveValidate': False,\n        ...         'disabled': False,\n        ...         'readonly': False,\n        ...         'omitExtraData': False,\n        ...         'liveOmit': False,\n        ...         'noValidate': False,\n        ...         'noHtml5Validate': False,\n        ...         'focusOnFirstError': False,\n        ...         'showErrorList': 'top'\n        ...     }\n        ... }\n        \n\n## OpenAPI Routes\n\nRepresents a collection of routes in an OpenAPI specification.\n\nEach instance of this class contains a list of `Route` objects, which can be accessed and manipulated as needed.\n\n\n    >>> from yaml import safe_load\n    >>> spec_yaml = '''\n    ... openapi: 3.0.3\n    ... paths:\n    ...   /items:\n    ...     get:\n    ...       summary: List items\n    ...       responses:\n    ...         '200':\n    ...           description: An array of items\n    ...     post:\n    ...       summary: Create item\n    ...       responses:\n    ...         '201':\n    ...           description: Item created\n    ... '''\n    >>> spec = safe_load(spec_yaml)\n    >>> routes = Routes(spec)\n    >>> len(routes)\n    2\n    >>> list(routes)\n    [('get', '/items'), ('post', '/items')]\n    >>> r = routes['get', '/items']\n    >>> r\n    Route(method='get', endpoint='/items')\n    >>> r.method_data\n    {'summary': 'List items', 'responses': {'200': {'description': 'An array of items'}}}\n\n",
    "bugtrack_url": null,
    "license": "apache-2.0",
    "summary": "JSON schema Utils",
    "version": "0.1.16",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "817d2f8d10f9b2c7e975fe910d6e6017132d9b57828d92c9f80d8bfe9a3f78dc",
                "md5": "1b12b45553dfbb9bddf6e6fd59e42ad9",
                "sha256": "07ddbad1cb6afa6a46c9f68d381fef7ac7cd99a16423073535682f1435de06ec"
            },
            "downloads": -1,
            "filename": "ju-0.1.16-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1b12b45553dfbb9bddf6e6fd59e42ad9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 34050,
            "upload_time": "2024-12-20T00:21:15",
            "upload_time_iso_8601": "2024-12-20T00:21:15.178785Z",
            "url": "https://files.pythonhosted.org/packages/81/7d/2f8d10f9b2c7e975fe910d6e6017132d9b57828d92c9f80d8bfe9a3f78dc/ju-0.1.16-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1fb1a877daa67052685f1b9c69e4118085b6d96b6def31c8975d665fe59c4ba4",
                "md5": "f76c76281e880b18791d22eab961adc9",
                "sha256": "9d54a1220dcd9b781afe7fdbc5f59fd42bec70b2e105bdf6c39fc67a7e1cb2f0"
            },
            "downloads": -1,
            "filename": "ju-0.1.16.tar.gz",
            "has_sig": false,
            "md5_digest": "f76c76281e880b18791d22eab961adc9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 30581,
            "upload_time": "2024-12-20T00:21:17",
            "upload_time_iso_8601": "2024-12-20T00:21:17.070502Z",
            "url": "https://files.pythonhosted.org/packages/1f/b1/a877daa67052685f1b9c69e4118085b6d96b6def31c8975d665fe59c4ba4/ju-0.1.16.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-20 00:21:17",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "ju"
}
        
Elapsed time: 9.28647s