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]

Project details


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 details)

Uploaded Source

Built Distribution

any_iter_to_html_table-0.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file any_iter_to_html_table-0.1.tar.gz.

File metadata

  • Download URL: any_iter_to_html_table-0.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for any_iter_to_html_table-0.1.tar.gz
Algorithm Hash digest
SHA256 ec4af8f805b6087f20df488e491baf24a3ce4fc9f95c02fb5a00c38a48fcff5b
MD5 7de03245de87e418b10ac6b423f7fdb6
BLAKE2b-256 616d90101f0895c000dc30cf17e84c1d3964ab8398c18d44689252cf1460b040

See more details on using hashes here.

File details

Details for the file any_iter_to_html_table-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for any_iter_to_html_table-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bc8456b316e013c0a3871c44cdcdf600e22c189e57472ca49170d87057cb23ac
MD5 69346657a4ed1d0a2de3f3ff13c8589d
BLAKE2b-256 85da1db59cc25ec60cc6c90bad11754d666d566a0d758895e8d044e5a38fb066

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page