Skip to main content

Integrates ChartFactor with Jupyter Notebooks

This project has been quarantined.

PyPI Admins need to review this project before it can be restored. While in quarantine, the project is not installable by clients, and cannot be being modified by its maintainers.

Read more in the project in quarantine help article.

Project description

ChartFactor for Python

How to install and test

After download the project go to the root directory

Uninstall any previous installation

python -m pip uninstall chartfactor --yes

Build the chartfactor package like this

python setup.py sdist

The previous command will create a dist folder with tha package in the chartfactor-1.0.tar.gz file.

Install the package locally

python -m pip install ./dist/chartfactor-1.0.tar.gz

Usage

Go to the Jupyter Notebook and in a new python notebook do the following

Cell 1

from chartfactor import cf
import pandas as pd

Cell 2

ts = pd.read_csv('./csvs/ticket_sales.csv')

Cell 3

jsonConfig = {
    "showRowNumber": False,
    "autoSizeColumns": False,
    "config": {
        "filters": [
            # {
            #     "path": "company",
            #     "operation": "TS",
            #     "value": [
            #         "pedia"
            #     ]
            # }
        ],
        "groups": [
            {
                "name": "catname",
                "label": "catname",
                "sort": {
                    "name": "commission",
                    "func": "sum",
                    "dir": "desc"
                },
                "limit": 10
            },
            {
                "name": "eventname",
                "label": "eventname",
                "sort": {
                    "name": "eventname",
                    "func": "unique",
                    "dir": "asc"
                },
                "limit": 5
            }
        ],
        "metrics": [
            {
                "name": "pricepaid",
                "func": "sum"
            }
        ],
        "fields": [

        ],
        "exclude": []
    },
    "rows": [],
    "limit": 8,
    "offset": 0,
    "visualization" : "Bars"
}

Cell 4

prov = cf.provider(ts, jsonConfig)
# prov.get_config()
# prov.run_count_query()
# prov.run_raw_query()
prov.visualize()

How to run test

  1. Make sure you are in a virtual environment where you have installed chartfactor-py
  2. Copy the funding_rounds.csv file from the data sources Google Drive folder to the chartfactor-py/tests/csv/funding_rounds.csv folder
  3. Change directories to the chartfactor-py/tests folder execute the following command:
python -m unittest

Increase jupyter notebook data rate limit

This may only be required on Windows environments. Run the following command in a terminal to generate the jupyter_notebook_config.py file if not exists:

jupyter notebook --generate-config

After that, locate the file in the .jupyter folder and add the following line at the end:

c.NotebookApp.iopub_data_rate_limit = 1.0e10

Configuring deployment credentials

Create and configure ~/.pypirc which is the pypi.org configuration file, in order to set the user and the token to upload the package.

  1. Create the file:
touch ~/.pypirc
  1. Assign permissions:
chmod 600 ~/.pypirc
  1. Open the file:
open ~/.pypirc
  1. Add this configuration:
[distutils]
index-servers =
    pypi
    testpypi

[pypi]
username = __token__
repository = https://upload.pypi.org/legacy/

[testpypi]
username = __token__
repository = https://test.pypi.org/legacy/

Notice that instead of using the password field, we are going to save the API tokens and passwords securely using keyring (which is installed by Twine):

  1. Configuring the test server:
keyring set https://test.pypi.org/legacy/ __token__
  1. Enter the generated token for the test environment:
Password for '__token__' in 'https://test.pypi.org/legacy/': TOKEN
  1. Configuring the production server:
keyring set https://upload.pypi.org/legacy/ __token__
  1. Enter the generated token for the production environment:
Password for '__token__' in 'https://upload.pypi.org/legacy/': TOKEN

Install Python Package Dependencies

To build the project successfully

pip install -r requirements.txt

To load packages for developers

pip install -r requirements-dev.txt

The execution of the command above will install if not exists the following packages:

  • twine>=3.7.1
  • build>=0.7.0
  • wheel>=0.37.1

If is necessary to upgrade the packages to a newer version just run the following command:

python3 -m pip install --upgrade {twine|build|wheel}

Code Obfuscation

The code obfuscation allows to modify a program code so that it is no longer useful to a hacker but remains fully functional.

Two processes to achieve code obfuscation and its corresponding deployment are detailed below.

Using pyarmor package to build a pyarmored wheel (Recommended)

Installing Anaconda

In order to create easily the virtual environments with the different python versions, and also obfuscate the code and be able to run the chartfactor-py package in every python version, it's necessary to install the Anaconda software.

First download it from the official website.

Next, open the software, go to the Environments tab, and create two virtual environment for python 3.6 and 3.7 with the following names:

  • env3.6
  • env3.7

Executing the build-pyarmored-wheel.sh file

The build-pyarmored-wheel.sh file was created to automatically build, obfuscate and deploy the package to the pypi.org server. After installing Anaconda successfully and created the virtual environments, execute the following command inside the chartfactor-py folder:

sh build-pyarmored-wheel.sh -v 1.x <-t|-p>

Flags:

  • -v package version
  • -t upload package to the test environment
  • -p upload package to the production environment

Using pyc-wheel package

This package allows you to compile all py files in a wheel to pyc files. For more information go to the pyc-wheel page

In the chartfactor-py folder execute the following build command:

python3 -m build

After execution, 2 files should have been generated in the dist folder:

  • chartfactor-1.x.tar.gz
  • chartfactor-1.x-py3-none-any.whl

Next, the following command must be executed to convert the .py files to .pyc (compiled and with the code obfuscated) inside the .whl file.

python -m pyc_wheel dist/chartfactor-1.x-py3-none-any.whl

You can add this option --with_backup to create a backup during the process.

Once the .whl file has been processed, it must be uploaded to the pypi.org or test.pypi.org repository, whichever the case may be.

To achieve that do the following:

Test server

python3 -m twine upload --repository testpypi ./*

Production server

python3 -m twine upload dist/*

For each case you must enter the user name __token__ and the provided token after.

To install the package run the following command:

pip uninstall chartfactor

Installing the Chartfactor.py package as an end-user

From test server

pip install -i https://test.pypi.org/simple/ chartfactor==1.x

From production server

python3 -m pip install chartfactor

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chartfactor-3.1.1.tar.gz (197.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chartfactor-3.1.1-py3-none-any.whl (5.8 MB view details)

Uploaded Python 3

File details

Details for the file chartfactor-3.1.1.tar.gz.

File metadata

  • Download URL: chartfactor-3.1.1.tar.gz
  • Upload date:
  • Size: 197.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for chartfactor-3.1.1.tar.gz
Algorithm Hash digest
SHA256 7b1ea2e56836bb4012619ec9d67af51a6b8a0bc198f1fdd89adfd637f130910e
MD5 2dad58f015d5bf408e88feffc9169b83
BLAKE2b-256 4a25ec51a3f4d865afb9bd60d4909e8d8adb5baf94eeec467062146999ed3dd2

See more details on using hashes here.

File details

Details for the file chartfactor-3.1.1-py3-none-any.whl.

File metadata

  • Download URL: chartfactor-3.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for chartfactor-3.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2cbe7f9adaa9b25ff81b0a7450af7f7b2cb2dd68f7d1883fc015052f687fd79f
MD5 85ef53b06804b7fff0bdd61a7d262883
BLAKE2b-256 2aaf85365d25eb1dba52a2153938ab5564a9be612fb0f7ac46cd5f9e0e90f0a4

See more details on using hashes here.

Supported by

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