Skip to main content

Convert any nested iterable (json, dict, list, tuple ...) to an HTML table. Design is separated from data.

Project description

Converts any nested iterable (json, dict, list ...) to an HTML table

    #pip install any-iter-to-html-table 

    from any_iter_to_html_table import create_html_table_from_iterable

    data = {

        "glossary": {

            "title": "example glossary",

            "GlossDiv": {

                "title": "S",

                "GlossList": {

                    "GlossEntry": {

                        "ID": "SGML",

                        "SortAs": "SGML",

                        "GlossTerm": "Standard Generalized Markup Language",

                        "Acronym": "SGML",

                        "Abbrev": "ISO 8879:1986",

                        "GlossDef": {

                            "para": "A meta-markup language, used to create markup languages such as DocBook.",

                            "GlossSeeAlso": ["GML", "XML"],

                        },

                        "GlossSee": "markup",

                    }

                },

            },

        }

    }



    """https://json.org/example.html"""  



        fromjsonorg_result = create_html_table_from_iterable(

        data, filename="fromjsonorg.html", title="Pandas - DataFrame", sparsify=True

    )

    jsonfile = r"F:\jsonstackoverflow.json"

    #'https://api.stackexchange.com/2.2/answers?order=desc&sort=activity&site=stackoverflow'

        json_from_file = create_html_table_from_iterable(

        jsonfile,

        filename="json_from_file.html",

        title="Pandas - DataFrame",

        sparsify=False,

    )

     sparsify=True

Without CSS

Design is separated from data. You can use the preset, but if you want,

you can easily create your own CSS style

    #'https://stackoverflow.com/questions/64359762/constructing-a-pandas-dataframe-with-columns-and-sub-columns-from-nested-diction

    nesteddict = {

        "level1": {

            "t1": {

                "s1": {"col1": 5, "col2": 4, "col3": 4, "col4": 9},

                "s2": {"col1": 1, "col2": 5, "col3": 4, "col4": 8},

                "s3": {"col1": 11, "col2": 8, "col3": 2, "col4": 9},

                "s4": {"col1": 5, "col2": 4, "col3": 4, "col4": 9},

            },

            "t2": {

                "s1": {"col1": 5, "col2": 4, "col3": 4, "col4": 9},

                "s2": {"col1": 1, "col2": 5, "col3": 4, "col4": 8},

                "s3": {"col1": 11, "col2": 8, "col3": 2, "col4": 9},

                "s4": {"col1": 5, "col2": 4, "col3": 4, "col4": 9},

            },

            "t3": {

                "s1": {"col1": 1, "col2": 2, "col3": 3, "col4": 4},

                "s2": {"col1": 5, "col2": 6, "col3": 7, "col4": 8},

                "s3": {"col1": 9, "col2": 10, "col3": 11, "col4": 12},

                "s4": {"col1": 13, "col2": 14, "col3": 15, "col4": 16},

            },

        },

        "level2": {

            "t1": {

                "s1": {"col1": 5, "col2": 4, "col3": 9, "col4": 9},

                "s2": {"col1": 1, "col2": 5, "col3": 4, "col4": 5},

                "s3": {"col1": 11, "col2": 8, "col3": 2, "col4": 13},

                "s4": {"col1": 5, "col2": 4, "col3": 4, "col4": 20},

            },

            "t2": {

                "s1": {"col1": 5, "col2": 4, "col3": 4, "col4": 9},

                "s2": {"col1": 1, "col2": 5, "col3": 4, "col4": 8},

                "s3": {"col1": 11, "col2": 8, "col3": 2, "col4": 9},

                "s4": {"col1": 5, "col2": 4, "col3": 4, "col4": 9},

            },

            "t3": {

                "s1": {"col1": 1, "col2": 2, "col3": 3, "col4": 4},

                "s2": {"col1": 5, "col2": 6, "col3": 7, "col4": 8},

                "s3": {"col1": 9, "col2": 10, "col3": 11, "col4": 12},

                "s4": {"col1": 13, "col2": 14, "col3": 15, "col4": 16},

            },

        },

    }   



        nested_dict = create_html_table_from_iterable(

        nesteddict,

        filename="from_nested_dict.html",

        title="Pandas - DataFrame",

        sparsify=False,

    )

    Convert any nested iterable to an HTML table. Design is separated from data. You can use the preset, but if you want,

    you can easily create your own CSS style.







        Parameters:

            data: Any

                You can pass any iterable (list, dict, tuple ), json file path (str) or json URL (str)

            filename: Union[None,str]

                File path for output, will be saved in your current working directory

                If None, no files will be written.

            title: str

                Title  for HTML

                (default =  'Pandas DataFrame')

            sparsify: bool

                Repeat keys in every line

                (default = False)



        Returns:

            tuple[str,str]

Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

any_iter_to_html_table-0.1.tar.gz (7.9 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page