Skip to main content

A package of functions for use in creating educational material.

Project description

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.

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.10", # 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.10-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.10*

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.

Project details


Download files

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

Source Distribution

class_functions-0.2.10.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

class_functions-0.2.10-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file class_functions-0.2.10.tar.gz.

File metadata

  • Download URL: class_functions-0.2.10.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for class_functions-0.2.10.tar.gz
Algorithm Hash digest
SHA256 4a0ba7e9ece48ff7ed6919fce560da08eafd0700e0cff9c47baae11fd9bf77ec
MD5 632a4798f2e9fe4364e74a2e3cd05b89
BLAKE2b-256 15b730ab68a37e6715f7554417117dad0466b4e5534a8c12a65ab57bbd069ba8

See more details on using hashes here.

File details

Details for the file class_functions-0.2.10-py3-none-any.whl.

File metadata

File hashes

Hashes for class_functions-0.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 6f4e4ceaa80fffbb413348a3cc71a15255ab8a3f3c8360c19a9a5384b59cf8e9
MD5 5361ca679c7e55ee8f58a7403c1d9e9a
BLAKE2b-256 bd13965c4bafabe0a58c28f74feea9f8cae7ccc2b481ac593fa1fba7a780a9d3

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