Popular Python Modules

I’m taking a poll of the python modules that TouchDesigner users have found useful in their work - aside from the one that we re-install like numpy. I want to make a list of modules for both new and experienced users, both familiar and not familiar with python. I’ll just start the list with one, haha:

os

[ This is following on a thread by ennui in 2014, but the world has changed since then. ]

So what do you think?

greg h

3 Likes

Ohh - I love this question.

Libraries I’ve used with TD more than once include:

  • Pandas - data analysis library
  • Sklearn - predictive data analysis
  • PyTorch (This is a bit of a reach given how frequently it changes) - open source machine learning
  • SciPy - open source library for scientific computing
  • Beautiful Soup - web scraping
  • Flask (This is a simple web server - which may already be addressed with the web sever DAT. That said, this is a lovely way to create web apps via python)

Those aside, it’d be great to see some extra helpers for additional support. Recently I’ve been doing a little work with a user to move data from TOPs to .ply files.

Haven’t used, but have looked at before:

  • Arrow - date and time library
  • Yagmail - gmail/smtp client
  • jijja - templating library - helpful for formatting HTML with temples

EDIT

  • Open3D - Open3D is an open-source library that supports rapid development of software that deals with 3D data.

I’d also use this as a quick moment to plug a nice virtual environment solution - or some handling for pip installs that land your project directory rather than in your OS or TD python libs. There’s also a great thread by @nettoyeur about package managment with poetry that might be worth adding to this conversation:

1 Like

shelve is a cool one, lots of similarity to Python Storage in TouchDesigner.
itertools

  • cycle()
  • combinations(), permutations(), product()

logging (my tox is here)
typing ← define argument types in functions

def my_function(name: str, num: float, dictionary: dict[str, str], item: typing.Any) -> int:
    return 0

tempfile ← manage creating/deleting temporary files.

warnings create your own warnings or suppress warnings from other modules.

These ones are quite common just like os

argparse parse arguments for scripts
csv read and write csv files
glob easiest way to find files
json read and write json, convert python objects to json
math common math functions or constants like math.ceil and math.sin and math.pi
multiprocessing In scripts outside of TouchDesigner, I prefer multiprocessing to asyncio for some tasks. I use Process, Pool, Manager, and Manager().Queue()
random

  • random()
  • randint(0,10) ← random integer between 0 and 10, including 10
  • choice([“a”,“b”,“c”]) ← random single choice from list
  • choices([“a”,“b”,“c”], k=2) ← random choice of 2 items, allowing duplicates

email send basic emails. my tox is here

re regular expressions

Non built-in modules:
ffmpy launch ffmpeg from python my scripts
watchdog watch for file changes on file system (my script)

3 Likes

Thanks so far… going forward, when you list a module, write a few words about what it’s good for, as most of us won’t know what it is, including me. thx

  • poetry
    manages your python libs/dependencies and basically allows to easily create tox packages

  • paho-mqtt
    mqtt client usefull when TDs native MQTT implementation isn’t fast enought

Good stuff in here and great question @greg

The following are up there on my list:

  • scipy - scientific computing, I just install this as a pre-req for sklearn below.
  • sklearn - some really cool stuff in here, I specifically make use of the vast clustering libraries for grouping large numbers of points into localized groups.
  • pyperclip - cross platform library for setting/getting clipboard data.
  • yaml - wasn’t this one included recently in 40k? can’t remember… anyways I’ve used this in the past for serializing python data that I can later re interpret back. Primarily I used it for saving/loading project data that I wanted humans to be able to read too.
1 Like

@lucasm Indeed, YAML is now in Experimental.

1 Like

Nice! Just out of curiosity, what prompted its inclusion on derivative’s end?

transitions - A python state machine library.

1 Like

Hey @lucasm,

wanted it for some openCV stuff.

cheers
Markus

1 Like

Hi all,

Would pyhull be interesting for generating geometry such as Voronoi and more? All the best, P
https://pythonhosted.org/pyhull/pyhull.html

Another good one I just discovered!
Humanize takes data in various formats, time, file size, etc and converts it to a slew of different human readable formats.

2 Likes

dataclasses is great for creating data structures with named and typed fields, with support for constructor parameters, conversion to/from dicts, and metadata that supports things like serialization.

1 Like
  • PyQRCode - Useful for generating QR codes for kiosks or photobooth download instructions
  • pypng - writing PNGs to file (used with PyQRCode)
  • request - useful for syncing with websites, updating assets, uploading assets (photo booth images for download on server)
  • pyTweening - used for fetching easing position for various easing functions
  • re - Regular Expression Parsing
1 Like

One more for the road -

  • natsort · PyPI, lots of applications and different use cases, I have been using this library to sort path strings (path/to/folder, and path/to/folder/subfolder, etc) into hierarchy aware, and alpha-numerically correct lists/orders. Really useful for building object outliner modules and such things.