Skip to main content

classFunctions

A few simple functions that I use for teaching and demonstrations. Some of them are quite useful beyond those settings.

There are also instructions for publishing your own functions to PyPI.org so that you can easily use them on multiple computers and share them with others.

Gradebook plotting functions

Both functions take the path to a Canvas gradebook CSV export. They find the assignment columns automatically, drop the test student and assignments with no submissions, and work whether or not there is a Yellowdig (YD) column.

from class_functions import assignmentPlots2, parallelCoordinatesPlot

# Box plot and strip plot of scores
assignmentPlots2("gradebook.csv")

# Interactive parallel coordinates plot; run once to see the abbreviated
# column names, then exclude any assignments you don't want
parallelCoordinatesPlot("gradebook.csv", cols_to_exclude=["Q1", "H3"])

Optional arguments for both: cols_to_exclude (list of abbreviated assignment names), normalize=True (scale scores to 0-1), replaceMissingWithZero=True.

Note: parallelCoordinatesPlot no longer takes numAssignments, startColIndex, or ydIndex.

Publish to PyPI

First, run the terminal command if you don't already have these packages installed.

pip install setuptools wheel twine

In addition to the .py file that contains the functions, you will want to create other files with the file structure shown below, but using the folder and function names that are unique to your package.

File structure

  • class_functions/
    • class_functions/
      • _init_.py
      • main.py
    • setup.py
    • README.md
    • requirements.txt

_init_.py

Make sure to add the new function name to this file when you add a new function.

from .main import tidyUpCols, assignmentPlots, relocate, ...

main.py

This file contains the code for the class_functions package. Enter new functions in here.

setup.py

Use the code below, but make sure to include the packages needed for your module. Do not include modules like math, io, datetime, sqlite3, contextlib, and json that come with the standard Python distribution.

from setuptools import setup, find_packages

# For using the README.md file as the project description
with open("README.md", "r") as f:
    description = f.read()

setup(
    name="class_functions",
    version="0.2.15", # Make sure to update this and the location of the whl file for each modification
    packages=find_packages(),
    install_requires=["pandas", "matplotlib", "seaborn", "plotly-express", "IPython"],
    # These next two lines are also needed to turn the README.md file into the project description
    long_description=description,
    long_description_content_type="text/markdown",
)

README.md

This is the README.md file.

requirements.txt

setuptools wheel twine

Create the distribution and whl files

Run the following shell command in the folder where setup.py is located:

python setup.py sdist bdist_wheel

Test locally

You can install this on your computer where your other Python libraries are located using the following terminal command from the folder where the setup.py file is located, but rather than the dist/class_functions... file, use the one for your module:

pip install dist/class_functions-0.2.15-py3-none-any.whl

If you need to reinstall it, run it with --force-reinstall to force installation of the whl file.

You can now run the terminal command pip list to see the package listed with the others on your computer. You can also try using functions in a new IPYNB or PY file just like any other package.

Upload to PyPI

First create an account on PyPI.org and create an API token. It's free to do so.

Then upload it using the following terminal command from the same folder as your setup.py file:

twine upload dist/*

If you just need to upload the files for a new version, then use this code:

twine upload dist/class_functions-0.2.15*

Be prepared to enter your API token. Alternatively, you can set environment variables so that they can be accessed as part of a workflow that does not need manual intervention. See below for how to do that. The environment variables and the values are:

TWINE_USERNAME="__token__"

TWINE_PASSWORD="get this from pypi.org"

Once It is uploaded, anyone can download and install the package using the terminal command:

pip install class-functions

Viewing and setting environment variables

Mac (Apple Silicon)

  • To view an individual variable, run the shell command echo $TWINE_PASSWORD
  • To view all the variables, run the shell command printenv or env
  • To view the file that contains all environment variables run the shell command vim ~/.zshrc
    • You can then add a new permanent one in there, and then be sure to run source ~/.zshrc to save and reload it.

Windows

  • GUI approach: Press Windows key → type "environment variables" and select the edit environment variables, which will bring up a window
  • To view an individual variable, run the shell command echo %TWINE_PASSWORD%
  • To view all the variables, run the shell command set
  • To create a new permanent environment variable, run the shell command setx TWINE_PASSWORD "py-dwelasdf3...and the rest of the token"
  • To view the file that contains all environment variables run the shell command vim ~/.zshrc
    • Close the shell and open a new session to see the new variable.

Hattip

Thanks to pixegami for the wonderful video detailing how to do this.

Metadata

Release files for class-functions 0.2.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for class-functions 0.2.15
File Size Uploaded
class_functions-0.2.15.tar.gz 18.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for class-functions 0.2.15
File Interpreter ABI Platform
class_functions-0.2.15-py3-none-any.whl Python 3 none any Details

Total release size: 37.0 kB

Release files / class_functions-0.2.15.tar.gz

Download URL class_functions-0.2.15.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8db31a80930a1f4d7df7ce9b1094c1bdfc5d0ce31f443438aedff6d6dc4a3ed9
BLAKE2b-256 checksum
How to use checksums
1639bd23dfcf174313dc060a7a4282adfba630b4005bfa67c0028fc1bcdfd6bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / class_functions-0.2.15-py3-none-any.whl

Download URL class_functions-0.2.15-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8422b51c23ea9ba2909b6ad4c5ed23e106a66a60b6e985067ded95934f7a9596
BLAKE2b-256 checksum
How to use checksums
7a26e0fc348bd80c033518f3efbb8d00109e90db66902abedb28e984e6f391c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.2.15 This release

2 release files

0.2.13

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page