Git Product home page Git Product logo

pybloqs's Introduction

pybloqs

CircleCI PyPI ReadTheDocs Coverage Status

PyBloqs is a flexible framework for visualizing data and automated creation of reports.

pybloqs in use in ipython notebook

ย 

It works with Pandas, matplotlib and highcharts. PyBloqs creates atomic blocks containing text, tables (from Pandas DataFrame), plots (matplotlib or highcharts) or images. All blocks can be styled with CSS. Each block can be created and displayed separately for fast development turnover. Lists of blocks can be stacked together to form reports. Reports can be displayed as HTML in the browser or exported in a variety of formats (including HTML, PDF, SVG, PNG).

Quickstart

Install PyBloqs

For a minimal install without HighCharts support run:

pip install pybloqs

or when installing in development mode:

python setup.py develop

This will allow you to run the example code below.

External dependencies

For full functionality, PyBloqs requires the following 3rd party programs and libraries. For some, the file location must be specified at install time:

pip install --install-option="INSTALL OPTIONS" git+https://github.com/manahl/pybloqs.git

e.g.

pip install --install-option="--highcharts=~/node_modules/highcharts/,~/node_modules/highcharts-heatmap/" git+https://github.com/manahl/pybloqs.git

wkhtmltopdf is not bundled with PyBloqs. You need to install it from your distribution's repository (Linux) or download it from the project page (https://wkhtmltopdf.org) . The binaries wkhtmltopdf and wkhtmltoimage are used for file output other than HTML. PyBloqs will search for the binaries on the system path. If you would like to use a local copy of the binaries, install with following option:

--wkhtmltopdf=/path/to/binary

When installing in development mode you can load wkhtmltopdf explicitly:

python setup.py load_wkhtmltopdf --wkhtmltopdf=/path/to/binary
  • Node.js with comander and puppeteer (optional; for PDF output with 'chrome_headless' backend). Please make sure these are available globally. In development mode, you can run
npm install

in the main PyBloqs directory.

  • Bokeh (optional). To install Bokeh dependency, you can use:
pip install pybloqs[bokeh]
  • Plotly (optional). To install Plotly dependency, you can use:
pip install pybloqs[plotly]

Highcharts is not bundled with PyBloqs. To create blocks with Highcharts plots, you need to download Highcharts separately (e.g. with npm install highcharts, npm install highcharts-heatmap etc.), and provide the path to your highcharts installation. Please make sure you have the right license for Highcharts. For full functionality you will need the following highcharts packages: highcharts, highcharts-heatmap, highcharts-funnel, highcharts-exporting, highcharts-export-csv (this example assumes, npm installed files into directory ~/node_modules).

--highcharts=~/node_modules/highcharts/,
~/node_modules/highcharts-heatmap/,~/node_modules/highcharts-funnel,~/node_modules/highcharts-exporting,
~/node_modules/highcharts-export-csv

When installing in development mode you can load highcharts explicitly (this example assumes, npm installed files into directory ~/node_modules)

python setup.py load_highcharts --highcharts=~/node_modules/highcharts/,~/node_modules/highcharts-heatmap/,\
~/node_modules/highcharts-funnel,~/node_modules/highcharts-exporting,~/node_modules/highcharts-export-csv

Using PyBloqs

from pybloqs import Block, HStack, VStack
import pandas as pd
from matplotlib import pyplot as plt

text_block = Block('This is a text block', styles={'text-align':'center', 'color':'blue'})
text_block.show()

df = pd.DataFrame([[1., 2.],[3.,4.]], columns =['a', 'b'])
table_block = Block(df)
table_block.show()

plot_block = Block(plt.plot(df['a'], df['b']))
plot_block.show()

plot_and_table = HStack([plot_block, table_block])
report = VStack([text_block, plot_and_table])
report.show()
report.save('report.pdf')

Configuration

You can specify per-user default parameters in a yaml-formatted file ~/.pybloqs.cfg. This config file allows you to setup a call setup and login sequence against an smtplib.SMTP (https://docs.python.org/2/library/smtplib.html#smtplib.SMTP) object. The following works for Google gmail - more details here (https://support.google.com/a/answer/176600?hl=en)

smtp_kwargs:
  host: smtp.gmail.com
  port: 587
smtp_pre_login_calls:
- !!python/tuple
  - ehlo
  - {}
- !!python/tuple
  - starttls
  - {}
- !!python/tuple
  - ehlo
  - {}
smtp_login:
  user: [email protected]
  password: a_secret
public_dir: /tmp
tmp_html_dir: /tmp
user_email_address: [email protected]

Documentation

Have a look at the detailed documentation.

Requirements

PyBloqs works with:

  • matplotlib
  • Pandas
  • html5lib
  • lxml
  • jinja2
  • markdown
  • beautifulsoup4
  • docutils

Acknowledgements

PyBloqs has been under active development at Man AHL since 2013.

Original concept and implementation: Tom Farnbauer

Contributors:

Contributions welcome!

License

PyBloqs is licensed under the GNU LGPL v2.1. A copy of which is included in LICENSE

pybloqs's People

Contributors

aliniknejad avatar arygr avatar bmoscon avatar chazkii avatar cozmacib avatar doddsiedodds avatar dominikmchrist avatar douglasbruce88 avatar edf825 avatar hanteo avatar hexabyte avatar jamesoliverh avatar jonnynye avatar lwfitzgerald avatar pablojim avatar rhodrich avatar skristof avatar swedishhh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pybloqs's Issues

HTML converters leave temporary files around

HTML converters generate temporary .html files that are not cleaned up after conversion to PDF or image files, which can potentially fill-up the system wide temporary folder (/tmp).

library doesn't work with pandas v2.0.x

Hi there,

I've noticed that the library doesn't work with pandas v2.0.x

AttributeError: 'Series' object has no attribute 'append'

or

'pandas.core.series.Series object' has no attribute 'iteritems'

Do you have a version compatible with the lastest version of pandas?

Best,
Giordano

Example with DataTables?

Hello,

I'm looking for an example on how to use DataTables.js with PyBloqs, is there one somewhere by chance? I looked at the code but am not sure where to start. Many thanks.

ID_PRECISION set at load time so cannot be reconfigured

It is easy to
import pybloqs
pybloqs.config.user_config['tmp_html_dir']='my temp directory'

conversely, since
pybloqs.block imports ID_PRECISIONat load time, it is tricky to change this. It would be better if instead, e.g. .show() would use self._id[:pybloqs.config.ID_PRECISION]

Cannot encode unicode characters when writing to pdf (python 2.7)

When attempting to write a unicode character using wkhtmltox, the following error message is seen running on python2.7:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)

This appears to be because the base block no longer utf-8 encodes it's render output.

Version Support and Platform Support

You know its going to come up eventually, so at a minimum it would be nice if the documentation and setup.py script/PyPi were updated to indicate what platforms are supported (MacOS? Windows?) and what versions of Python are supported. I saw only 2.7 wheels/eggs on PyPi. Is Python3 supported?

unit test failure - No such file or directory: 'PyBloqs/pybloqs/static/highstock.js'

clean install of Pybloqs on a 2.7 environment. setup.py develop, Installed whkhtmltopdf and setup.py load_wkhtmltopdf --wkhtmltopdf=...

then setup.py test

there were 13 test failures, all with the same signature. Is there an non obvious step? The only thing I didn't do was install highcharts, since the readme indicated it was optional.

______________________________ test_scatter_plot _______________________________

    @wraps(func)
    def generate_and_check():
        # Generate the block
        block = func()
>       tmp_file = block.save(fmt=fmt, **kwargs)

tests/integration/generate/generation_framework.py:31: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pybloqs/block/base.py:175: in save
    content = self.render_html(static_output=False, header_block=header_block, footer_block=footer_block)
pybloqs/block/base.py:119: in render_html
    res.write(head)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pybloqs.static.JScript object at 0x7fbf3cccfc90>
parent = <head><script type="text/javascript">if(typeof(_pybloqs_load_sentinel_jsinflat... block;\n    margin-left: 1em;\n    font-family: monospace;\n}\n</style></head>

    def write(self, parent=None):
        stream = StringIO()
    
        # Write out init condition
        stream.write("if(typeof(%s) == 'undefined'){" % self._sentinel_var_name)
    
>       with open(self._local_path, "rb") as f:
E       IOError: [Errno 2] No such file or directory: '/home/bryant/PyBloqs/pybloqs/static/highstock.js'

pybloqs/static/__init__.py:70: IOError

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.