dfimg


Namedfimg JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryA library to convert polars/ pandas dataframes to image.
upload_time2025-01-28 06:41:32
maintainerNone
docs_urlNone
authorTapanhaz tapanhaz@gmail.com
requires_python<4.0,>=3.9
licenseMIT
keywords dataframe image pandas polars pillow
VCS
bugtrack_url
requirements polars pandas pillow requests beautifulsoup4
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dfimg
Convert polars / pandas dataframe to image/ binary image. 

## Installation ::

For intallation use pip :

```shell
pip install dfimg
```

## Functions ::

dfimg provides the following functions:

df_to_html_img:
    This function performs the main task of converting a Polars or Pandas DataFrame to an HTML or PIL image.

    Parameters:
        dataframe (required): The Polars or Pandas DataFrame to be converted.
        title (optional): Title string to display on top of the image. Default is an empty string.
        image_title_font (optional): Font to be used for the title. Default is None.
        image_table_font (optional): Font for the table content. Default is None.
        image_title_font_size (optional): Font size for the title. Default is 16.
        image_table_font_size (optional): Font size for the table content. Default is 12.
        image_cells_border_color (optional): Color for cell borders. Default is None.
        style (optional): Styles for the html table. Default             
                            {
                                "bg-color": "white", 
                                "color": "black", 
                                "font-weight": "normal"
                            }
        tbl_style (optional): Table-specific styles, default 
                            {
                                "bg-color": "white", 
                                "color": "black", 
                                "font-weight": "normal"
                            }
        header_style (optional): Style for the table header, Default 
                                {
                                    "bg-color": "DarkViolet", 
                                    "color": "white", 
                                    "font-weight": "bold"
                                }
        highlight_conditions (optional): A dictionary for conditional formatting. 
                                        For example, look below.
                                        
        column_style (optional): Dictionary of styles for columns. This will override content_based_style if both are provided.

        content_based_style (optional): Dictionary of styles based on content. The style will be applied for all column of same datatype 

        Supported keys are "String", "Int", "Float", "Boolean", "Datetime", "Date", "Time" and "Others". For example look below
        table_formatting (optional): Format of the table in the image. Possible values are:
            "ASCII_FULL"
            "ASCII_FULL_CONDENSED"
            "ASCII_NO_BORDERS"
            "ASCII_BORDERS_ONLY"
            "ASCII_BORDERS_ONLY_CONDENSED"
            "ASCII_HORIZONTAL_ONLY"
            "ASCII_MARKDOWN"
            "MARKDOWN"
            "NOTHING" Default is "ASCII_MARKDOWN".

        cell_padding (optional): Padding inside image cells. Default is 10.
        min_cell_width (optional): Minimum width for each image cell. Default is 100.
        float_precision (optional): Decimal precision for floating-point numbers. Default is 2.
        thousands_separator (optional): Character to use as a thousands separator. Default is _.
        return_type (optional): Type of output. Options are:

            "html" -> returns html string of the dataframe
            "pil_image" -> return PIL Image.
            Default is "pil_image".

image_to_bin:
    This function convert PIL Image to binary.

    Parameters:
        img (required): A PIL Image object.
        format (optional): The image format of the resultant binary(e.g., "PNG", "JPEG", etc.). Default is "PNG".
        
send_img_to_telegram:
    This is a addon function for sending PIL Image to Telegram chat via the Telegram Bot API.
    
    Parameters:
        img (required): A PIL Image object that you want to send to Telegram.
        chat_id (required): The chat ID of the recipient on Telegram.
        bot_token (required): Your Telegram bot token.
        img_name (optional): The name of the image file (without extension). Default is "sample".
        format (optional): The format of the image to send (e.g., "PNG", "JPEG"). Default is "PNG".

## Example ::

```python
import polars as pl
from datetime import datetime, date, time
from dfimg import df_to_html_img, send_img_to_telegram, image_to_bin

data = {
    "Title": ["x", "y", "z"],
    "Datetime": [datetime(2023, 1, 1), datetime(2023, 2, 1), datetime(2023, 3, 1)],
    "Date": [date(2023, 1, 1), date(2023, 2, 1), date(2023, 3, 1)],    
    "Time": [time(12, 0, 0), time(12, 0, 0), time(12, 0, 0)],
    "Int_col": [10, 20, 30],
    "Str_col": ["str1", "str2", "str3"],
    "Float_col": [1.5, 2.5, 3.5],
    "Bool_col": [True, False, True]
}

img = df_to_html_img(
        pl.DataFrame(data),
        title= "TEST",
        content_based_style= {
                        "String": {
                            "bg-color": "LightCoral", 
                            "color": "DodgerBlue", 
                            "font-weight": "bolder"
                            }
                        },
        highlight_conditions= {
                        "Int_col": {
                                "condition": ">= 20", 
                                "bg-color": "yellow", 
                                "color": "green"
                                },
                        "Str_col": {
                                "condition": ".__contains__('str2')", 
                                "bg-color": "yellow", 
                                "color": "green"
                                },
                        "Bool_col": {
                                "condition": True, 
                                "bg-color": "yellow", 
                                "color": "green"
                                }
                            }
    )

# If your want to save the image locally:
img.save("image.png")

#for converting PIL Image to binary.

img_binary = image_to_bin(img)

#For sending image to telegram 

send_img_to_telegram(
                img= img, 
                chat_id= "xxxxxxxxx", 
                bot_token= "xxxxxxx:xxxxxxxxx"
                )


```

## Example Image ::
![Example](img/image.png)


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "dfimg",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "dataframe, image, pandas, polars, pillow",
    "author": "Tapanhaz tapanhaz@gmail.com",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/8f/ea/aac3af4eacb2de44298bada7b958b3fde16dd66141d59bd4f1bc587fff03/dfimg-0.1.2.tar.gz",
    "platform": null,
    "description": "# dfimg\nConvert polars / pandas dataframe to image/ binary image. \n\n## Installation ::\n\nFor intallation use pip :\n\n```shell\npip install dfimg\n```\n\n## Functions ::\n\ndfimg provides the following functions:\n\ndf_to_html_img:\n    This function performs the main task of converting a Polars or Pandas DataFrame to an HTML or PIL image.\n\n    Parameters:\n        dataframe (required): The Polars or Pandas DataFrame to be converted.\n        title (optional): Title string to display on top of the image. Default is an empty string.\n        image_title_font (optional): Font to be used for the title. Default is None.\n        image_table_font (optional): Font for the table content. Default is None.\n        image_title_font_size (optional): Font size for the title. Default is 16.\n        image_table_font_size (optional): Font size for the table content. Default is 12.\n        image_cells_border_color (optional): Color for cell borders. Default is None.\n        style (optional): Styles for the html table. Default             \n                            {\n                                \"bg-color\": \"white\", \n                                \"color\": \"black\", \n                                \"font-weight\": \"normal\"\n                            }\n        tbl_style (optional): Table-specific styles, default \n                            {\n                                \"bg-color\": \"white\", \n                                \"color\": \"black\", \n                                \"font-weight\": \"normal\"\n                            }\n        header_style (optional): Style for the table header, Default \n                                {\n                                    \"bg-color\": \"DarkViolet\", \n                                    \"color\": \"white\", \n                                    \"font-weight\": \"bold\"\n                                }\n        highlight_conditions (optional): A dictionary for conditional formatting. \n                                        For example, look below.\n                                        \n        column_style (optional): Dictionary of styles for columns. This will override content_based_style if both are provided.\n\n        content_based_style (optional): Dictionary of styles based on content. The style will be applied for all column of same datatype \n\n        Supported keys are \"String\", \"Int\", \"Float\", \"Boolean\", \"Datetime\", \"Date\", \"Time\" and \"Others\". For example look below\n        table_formatting (optional): Format of the table in the image. Possible values are:\n            \"ASCII_FULL\"\n            \"ASCII_FULL_CONDENSED\"\n            \"ASCII_NO_BORDERS\"\n            \"ASCII_BORDERS_ONLY\"\n            \"ASCII_BORDERS_ONLY_CONDENSED\"\n            \"ASCII_HORIZONTAL_ONLY\"\n            \"ASCII_MARKDOWN\"\n            \"MARKDOWN\"\n            \"NOTHING\" Default is \"ASCII_MARKDOWN\".\n\n        cell_padding (optional): Padding inside image cells. Default is 10.\n        min_cell_width (optional): Minimum width for each image cell. Default is 100.\n        float_precision (optional): Decimal precision for floating-point numbers. Default is 2.\n        thousands_separator (optional): Character to use as a thousands separator. Default is _.\n        return_type (optional): Type of output. Options are:\n\n            \"html\" -> returns html string of the dataframe\n            \"pil_image\" -> return PIL Image.\n            Default is \"pil_image\".\n\nimage_to_bin:\n    This function convert PIL Image to binary.\n\n    Parameters:\n        img (required): A PIL Image object.\n        format (optional): The image format of the resultant binary(e.g., \"PNG\", \"JPEG\", etc.). Default is \"PNG\".\n        \nsend_img_to_telegram:\n    This is a addon function for sending PIL Image to Telegram chat via the Telegram Bot API.\n    \n    Parameters:\n        img (required): A PIL Image object that you want to send to Telegram.\n        chat_id (required): The chat ID of the recipient on Telegram.\n        bot_token (required): Your Telegram bot token.\n        img_name (optional): The name of the image file (without extension). Default is \"sample\".\n        format (optional): The format of the image to send (e.g., \"PNG\", \"JPEG\"). Default is \"PNG\".\n\n## Example ::\n\n```python\nimport polars as pl\nfrom datetime import datetime, date, time\nfrom dfimg import df_to_html_img, send_img_to_telegram, image_to_bin\n\ndata = {\n    \"Title\": [\"x\", \"y\", \"z\"],\n    \"Datetime\": [datetime(2023, 1, 1), datetime(2023, 2, 1), datetime(2023, 3, 1)],\n    \"Date\": [date(2023, 1, 1), date(2023, 2, 1), date(2023, 3, 1)],    \n    \"Time\": [time(12, 0, 0), time(12, 0, 0), time(12, 0, 0)],\n    \"Int_col\": [10, 20, 30],\n    \"Str_col\": [\"str1\", \"str2\", \"str3\"],\n    \"Float_col\": [1.5, 2.5, 3.5],\n    \"Bool_col\": [True, False, True]\n}\n\nimg = df_to_html_img(\n        pl.DataFrame(data),\n        title= \"TEST\",\n        content_based_style= {\n                        \"String\": {\n                            \"bg-color\": \"LightCoral\", \n                            \"color\": \"DodgerBlue\", \n                            \"font-weight\": \"bolder\"\n                            }\n                        },\n        highlight_conditions= {\n                        \"Int_col\": {\n                                \"condition\": \">= 20\", \n                                \"bg-color\": \"yellow\", \n                                \"color\": \"green\"\n                                },\n                        \"Str_col\": {\n                                \"condition\": \".__contains__('str2')\", \n                                \"bg-color\": \"yellow\", \n                                \"color\": \"green\"\n                                },\n                        \"Bool_col\": {\n                                \"condition\": True, \n                                \"bg-color\": \"yellow\", \n                                \"color\": \"green\"\n                                }\n                            }\n    )\n\n# If your want to save the image locally:\nimg.save(\"image.png\")\n\n#for converting PIL Image to binary.\n\nimg_binary = image_to_bin(img)\n\n#For sending image to telegram \n\nsend_img_to_telegram(\n                img= img, \n                chat_id= \"xxxxxxxxx\", \n                bot_token= \"xxxxxxx:xxxxxxxxx\"\n                )\n\n\n```\n\n## Example Image ::\n![Example](img/image.png)\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A library to convert polars/ pandas dataframes to image.",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/Tapanhaz/dfimg",
        "Repository": "https://github.com/Tapanhaz/dfimg"
    },
    "split_keywords": [
        "dataframe",
        " image",
        " pandas",
        " polars",
        " pillow"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d003e623531e83eace5bb6633d363b0122f40fd8e8af7bc6101aec1e6f2e6d3a",
                "md5": "9bf6a1b4bce6d3ef6529a95665a31455",
                "sha256": "763e7017102e81843210a825e94a1a33b99e303554a63c8bfa41bad3d967fca2"
            },
            "downloads": -1,
            "filename": "dfimg-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9bf6a1b4bce6d3ef6529a95665a31455",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 7081,
            "upload_time": "2025-01-28T06:41:30",
            "upload_time_iso_8601": "2025-01-28T06:41:30.706520Z",
            "url": "https://files.pythonhosted.org/packages/d0/03/e623531e83eace5bb6633d363b0122f40fd8e8af7bc6101aec1e6f2e6d3a/dfimg-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8feaaac3af4eacb2de44298bada7b958b3fde16dd66141d59bd4f1bc587fff03",
                "md5": "fda2a8680db3b1d63565423b94b9a5d3",
                "sha256": "4381cb0bc95a26c45f2d3becff33db0042e5334f0eec9b0e955d8b605119ab9c"
            },
            "downloads": -1,
            "filename": "dfimg-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "fda2a8680db3b1d63565423b94b9a5d3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 6123,
            "upload_time": "2025-01-28T06:41:32",
            "upload_time_iso_8601": "2025-01-28T06:41:32.068107Z",
            "url": "https://files.pythonhosted.org/packages/8f/ea/aac3af4eacb2de44298bada7b958b3fde16dd66141d59bd4f1bc587fff03/dfimg-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-28 06:41:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Tapanhaz",
    "github_project": "dfimg",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "polars",
            "specs": []
        },
        {
            "name": "pandas",
            "specs": []
        },
        {
            "name": "pillow",
            "specs": []
        },
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "beautifulsoup4",
            "specs": []
        }
    ],
    "lcname": "dfimg"
}
        
Elapsed time: 1.03755s