Skip to content

Commit 0689fab

Browse files
committed
Initial commit
1 parent a389268 commit 0689fab

10 files changed

Lines changed: 458 additions & 1 deletion

File tree

.gitignore

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
venv
2+
3+
### Vim ###
4+
[._]*.s[a-w][a-z]
5+
[._]s[a-w][a-z]
6+
*.un~
7+
Session.vim
8+
.netrwhist
9+
*~
10+
11+
12+
### OSX ###
13+
.DS_Store
14+
.AppleDouble
15+
.LSOverride
16+
17+
# Icon must end with two \r
18+
Icon
19+
20+
21+
# Thumbnails
22+
._*
23+
24+
# Files that might appear in the root of a volume
25+
.DocumentRevisions-V100
26+
.fseventsd
27+
.Spotlight-V100
28+
.TemporaryItems
29+
.Trashes
30+
.VolumeIcon.icns
31+
32+
# Directories potentially created on remote AFP share
33+
.AppleDB
34+
.AppleDesktop
35+
Network Trash Folder
36+
Temporary Items
37+
.apdisk
38+
39+
40+
### Python ###
41+
# Byte-compiled / optimized / DLL files
42+
__pycache__/
43+
*.py[cod]
44+
*$py.class
45+
46+
# C extensions
47+
*.so
48+
49+
# Distribution / packaging
50+
.Python
51+
env/
52+
build/
53+
develop-eggs/
54+
dist/
55+
downloads/
56+
eggs/
57+
.eggs/
58+
lib/
59+
lib64/
60+
parts/
61+
sdist/
62+
var/
63+
*.egg-info/
64+
.installed.cfg
65+
*.egg
66+
67+
# PyInstaller
68+
# Usually these files are written by a python script from a template
69+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
70+
*.manifest
71+
*.spec
72+
73+
# Installer logs
74+
pip-log.txt
75+
pip-delete-this-directory.txt
76+
77+
# Unit test / coverage reports
78+
htmlcov/
79+
.tox/
80+
.coverage
81+
.coverage.*
82+
.cache
83+
nosetests.xml
84+
coverage.xml
85+
*,cover
86+
87+
# Translations
88+
*.mo
89+
*.pot
90+
91+
# Django stuff:
92+
*.log
93+
94+
# Sphinx documentation
95+
docs/_build/
96+
97+
# PyBuilder
98+
target/
99+
100+
101+
### Node ###
102+
# Logs
103+
logs
104+
*.log
105+
npm-debug.log*
106+
107+
# Runtime data
108+
pids
109+
*.pid
110+
*.seed
111+
112+
# Directory for instrumented libs generated by jscoverage/JSCover
113+
lib-cov
114+
115+
# Coverage directory used by tools like istanbul
116+
coverage
117+
118+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
119+
.grunt
120+
121+
# node-waf configuration
122+
.lock-wscript
123+
124+
# Compiled binary addons (http://nodejs.org/api/addons.html)
125+
build/Release
126+
127+
# Dependency directory
128+
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
129+
node_modules
130+

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: python
2+
python:
3+
- 3.7
4+
install:
5+
- pip install poetry
6+
script:
7+
- poetry install && poetry run python tests.py
8+

README.md

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,91 @@
11
# quickchart-python
2-
Python client for quickchart.io image charts web service
2+
3+
A Python client for the [quickchart.io](https://quickchart.io/) image charts web service.
4+
5+
# Installation
6+
7+
Use the `quickchart.py` library in this project, or install through pip:
8+
9+
```
10+
pip install quickchart
11+
```
12+
13+
# Usage
14+
15+
This library provides a `QuickChart` class. Import and instantiate it. Then set properties on it and specify a [Chart.js](https://chartjs.org) config:
16+
17+
```python
18+
from quickchart import QuickChart
19+
20+
qc = QuickChart()
21+
qc.width = 500
22+
qc.height = 300
23+
qc.device_pixel_ratio = 2.0
24+
qc.config = {
25+
"type": "bar",
26+
"data": {
27+
"labels": ["Hello world", "Test"],
28+
"datasets": [{
29+
"label": "Foo",
30+
"data": [1, 2]
31+
}]
32+
}
33+
}
34+
35+
Use `get_url()` on your quickchart object to get the encoded URL that renders your chart:
36+
37+
```python
38+
print(qc.get_url())
39+
# https://quickchart.io/chart?c=%7B%22chart%22%3A+%7B%22type%22%3A+%22bar%22%2C+%22data%22%3A+%7B%22labels%22%3A+%5B%22Hello+world%22%2C+%22Test%22%5D%2C+%22datasets%22%3A+%5B%7B%22label%22%3A+%22Foo%22%2C+%22data%22%3A+%5B1%2C+2%5D%7D%5D%7D%7D%7D&w=600&h=300&bkg=%23ffffff&devicePixelRatio=2.0&f=png
40+
```
41+
42+
If you have a long or complicated chart, use `get_short_url()` to get a fixed-length URL using the quickchart.io web service (note that these URLs only persist for a short time unless you have a subscription):
43+
44+
```python
45+
print(qc.get_short_url())
46+
# https://quickchart.io/chart/render/f-a1d3e804-dfea-442c-88b0-9801b9808401
47+
```
48+
49+
The URLs will render an image of a chart:
50+
51+
<img src="https://quickchart.io/chart?c=%7B%22type%22%3A+%22bar%22%2C+%22data%22%3A+%7B%22labels%22%3A+%5B%22Hello+world%22%2C+%22Test%22%5D%2C+%22datasets%22%3A+%5B%7B%22label%22%3A+%22Foo%22%2C+%22data%22%3A+%5B1%2C+2%5D%7D%5D%7D%7D&w=600&h=300&bkg=%23ffffff&devicePixelRatio=2.0&f=png" width="500" />
52+
53+
## Customizing your chart
54+
55+
You can set the following properties:
56+
57+
### config: dict
58+
The actual Chart.js chart configuration.
59+
60+
### width: int
61+
Width of the chart image in pixels. Defaults to 500
62+
63+
### height: int
64+
Height of the chart image in pixels. Defaults to 300
65+
66+
### format: str
67+
Format of the chart. Defaults to png. svg is also valid.
68+
69+
### background_color: str
70+
The background color of the chart. Any valid HTML color works. Defaults to #ffffff (white). Also takes rgb, rgba, and hsl values.
71+
72+
### device_pixel_ratio: float
73+
The device pixel ratio of the chart. This will multiply the number of pixels by the value. This is usually used for retina displays. Defaults to 1.0.
74+
75+
## Getting URLs
76+
77+
There are two ways to get a URL for your chart object.
78+
79+
### getUrl(): string
80+
81+
Returns a URL that will display the chart image when loaded.
82+
83+
### getShortUrl(): Promise
84+
85+
Uses the quickchart.io web service to create a fixed-length chart URL that displays the chart image. The Promise resolves with a URL such as `https://quickchart.io/chart/render/f-a1d3e804-dfea-442c-88b0-9801b9808401`.
86+
87+
Note that short URLs expire after a few days for users of the free service. You can [subscribe](https://quickchart.io/pricing/) to keep them around longer.
88+
89+
## More examples
90+
91+
Checkout the `examples` directory to see other usage.

__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from quickchart import *

examples/long_url_example.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from quickchart import QuickChart
2+
3+
qc = QuickChart()
4+
qc.config = {
5+
"type": "bar",
6+
"data": {
7+
"labels": ["Hello world", "Test"],
8+
"datasets": [{
9+
"label": "Foo",
10+
# Count from 0 to 100
11+
"data": list(range(0, 100)),
12+
}]
13+
}
14+
}
15+
16+
print(qc.get_short_url())
17+
# https://quickchart.io/chart/render/f-b4bf9221-0499-4bc6-b1ae-6f7c78be9d93

examples/simple_example.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from quickchart import QuickChart
2+
3+
qc = QuickChart()
4+
qc.width = 600
5+
qc.height = 300
6+
qc.device_pixel_ratio = 2.0
7+
qc.config = {
8+
"type": "bar",
9+
"data": {
10+
"labels": ["Hello world", "Test"],
11+
"datasets": [{
12+
"label": "Foo",
13+
"data": [1, 2]
14+
}]
15+
}
16+
}
17+
18+
print(qc.get_url())
19+
# https://quickchart.io/chart?c=%7B%22type%22%3A+%22bar%22%2C+%22data%22%3A+%7B%22labels%22%3A+%5B%22Hello+world%22%2C+%22Test%22%5D%2C+%22datasets%22%3A+%5B%7B%22label%22%3A+%22Foo%22%2C+%22data%22%3A+%5B1%2C+2%5D%7D%5D%7D%7D&w=600&h=300&bkg=%23ffffff&devicePixelRatio=2.0&f=png

poetry.lock

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tool.poetry]
2+
name = "quickchart"
3+
version = "0.1.0"
4+
description = "A client for quickchart.io, a service that generates static chart images"
5+
authors = ["Ian Webster <ianw_pypi@ianww.com>"]
6+
license = "MIT"
7+
8+
[tool.poetry.dependencies]
9+
python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
10+
requests = "^2.23.0"
11+
12+
[tool.poetry.dev-dependencies]
13+
14+
[build-system]
15+
requires = ["poetry>=0.12"]
16+
build-backend = "poetry.masonry.api"

0 commit comments

Comments
 (0)