SkillAgentSearch skills...

Python

⚡️Official Image-charts Python library

Install / Use

/learn @image-charts/Python

README

image charts python library logo

Pypi VERSION

Libraries.io dependency status for GitHub repo Code Climate maintainability

Official Image Charts API client. Generate URLs of static image charts. Embed them everywhere in emails, pdf reports, chat bots...!

Getting started

1. Install Image-Charts Python Package

pip install image-charts

2. Import Image-Charts library

from ImageCharts import ImageCharts

3. Generate a chart image

pie = ImageCharts().cht('p').chd('a:2.5,5,8.3').chs('100x100')

pie.to_url()) # https://image-charts.com/chart?chd=a%3A2.5%2C5%2C8.3&chs=600x300&cht=p
pie.to_file('/path/to/chart.png'); #
pie.to_data_uri() # data:image/png;base64,iVBORw0KGgo...
pie.to_binary() # b'\x89PNG\r\n\x1a\n\x00\x00...
<p align="center"> <a href="https://www.image-charts.com/"> <img src="https://image-charts.com/chart?cht=bvs&chd=s:theresadifferencebetweenknowingthepathandwalkingthepath&chs=700x200&chxt=y&chf=b0,lg,90,4CA4F5,0.1,C371D3,0.8,EA469E,1" /> </a> </p>

Table of Contents


Constructor

Create an instance, the argument within [ ] is optional. See usage

ImageCharts( [ Dict opt ] )

Options

Default options are listed below.

opt = {
    #
    # Request timeout (in millisecond) when calling to_binary() or to_data_uri()
    #
    'timeout': 5000,

    #
    # (Enterprise and Enterprise+ subscription only) SECRET_KEY
    #
    'secret': null,

    #
    # (Enterprise, Enterprise+ and On-Premise subscription only) custom domain
    #
    'host': 'image-charts.com',

    #
    # (On-Premise subscription only) custom protocol
    #
    'protocol': 'https',

    #
    # (On-Premise subscription only) custom port
    #
    'port': 443,

    #
    # (On-Premise subscription only) custom pathname
    #
    'pathname': '/chart'
}

Methods


<a name="to_url"></a>

to_url() : String

Get the full Image-Charts API url (signed and encoded if necessary)

Usage
from ImageCharts import ImageCharts

# vertical bar chart
# 300px x 300px
# 2 data points: 60 and 40
# get the generated URL
chart_url = ImageCharts().cht('bvg') .chs('300x300') .chd('a:60,40') .to_url()

print(chart_url) # https://image-charts.com/chart?cht=bvg&chs=300x300&chd=a%3A60%2C40


<a name="to_file"></a>

to_file() : String

Creates a file containing generated chart image (blocking)

Usage
from ImageCharts import ImageCharts

# genertates a
# vertical bar chart (cht=bvg)
# of 300px x 300px (chs=300x300)
# with 2 data points: 60 and 40 (chd=a:60,40)
# and write it to /tmp/chart.png

ImageCharts().cht('bvg').chs('300x300').chd('a:60,40').to_file('/tmp/awesome_chart.png')


<a name="to_binary"></a>

to_binary() : Buffer

Do a request to Image-Charts API with current configuration and yield image data as bytes

Usage
from ImageCharts import ImageCharts

# vertical bar chart
# 300px x 300px
# 2 data points: 60 and 40
# download chart image

chart_url = ImageCharts().cht('bvg').chs('300x300').chd('a:60,40').to_binary()
print(chart_url) # b'\x89PNG\r\n\x1a\n\x00\x00...


<a name="to_data_uri"></a>

to_data_uri() : String

Do a blocking request to Image-Charts API with current configuration and yield a base64 encoded data URI

Usage
from ImageCharts import ImageCharts

# vertical bar chart
# 300px x 300px
# 2 data points: 60 and 40
# download chart image and generate a data URI string

chart_url = ImageCharts().cht('bvg').chs('300x300').chd('a:60,40').to_data_uri()

print(chart_url) # "data:image/png;base64,iVBORw0KGgo...


Enterprise Support

Image-Charts Enterprise and Enterprise+ subscriptions remove the watermark and enable advanced features like custom-domain, high-resolution charts, custom fonts, multiple axis and mixed charts.

Usage

Once subscribed to a plan you will receive an ACCOUNT_ID and a SECRET_KEY. These two parameters are mandatory to sign your request and remove the watermark. Replace both values in the code example below:

from ImageCharts import ImageCharts

# pie chart
# 700px x 190px
# 2 data points: 60 and 40
# 1 label per pie slice : "Hello" and "World"
# 1 gradient per pie slice
# enable paid-only features like high-resolution charts
# get the whole (HMAC signed) URL

chart_url = ImageCharts({'secret': 'SECRET_KEY'}).icac('ACCOUNT_ID').cht('p3').chs('700x190').chd('t:60,40').chl('Hello|World').chf('ps0-0,lg,45,ffeb3b,0.2,f44336,1|ps0-1,lg,45,8bc34a,0.2,009688,1').icretina('1').to_url()

print(chart_url)
# https://image-charts.com/chart?chd=t%3A60%2C40&chf=ps0-0%2Clg%2C45%2Cffeb3b%2C0.2%2Cf44336%2C1%7Cps0-1%2Clg%2C45%2C8bc34a%2C0.2%2C009688%2C1&chl=Hello%7CWorld&chs=700x190&cht=p3&icac=documentation&icretina=1&ichm=122242bb700d825d69b3fafe4ec67193b45dcfe0ed93fcca307e0d0a84b73ea2

<p align="center"><img src="https://image-charts.com/chart?chd=t%3A60%2C40&chf=ps0-0%2Clg%2C45%2Cffeb3b%2C0.2%2Cf44336%2C1%7Cps0-1%2Clg%2C45%2C8bc34a%2C0.2%2C009688%2C1&chl=Hello%7CWorld&chs=700x190&cht=p3&icac=documentation&icretina=1&ichm=122242bb700d825d69b3fafe4ec67193b45dcfe0ed93fcca307e0d0a84b73ea2"/></p>

On-Premise Support

Image-Charts virtual appliance can be deployed anywhere inside

View on GitHub
GitHub Stars12
CategoryDevelopment
Updated2d ago
Forks1

Languages

Python

Security Score

80/100

Audited on Mar 30, 2026

No findings