I'm working on a Python3 script that uses pyobjc to access the macOS clipboard via NSPasteboard. To do this, it requires the following import:
from AppKit import NSPasteboard
In order to keep my distribution to a minimum size (the full pyobjc 9.2 package is 30MB), I wanted to find out the smallest set of files needed in order to allow this import to succeed. Through trial-and-error (using a REPL and attempting to import NSPasteboard, looking at the stack trace errors and adding in missing modules one by one), I determined this to be:
./lib
├── AppKit
├── CoreFoundation
├── Foundation
├── objc
└── PyObjCTools
This slimmed set is only 7MB by comparison.
My question is: is there a more pragmatic way to determine this? Using importlib or something similar?
These commands give minimum imports :
Update
This script gets the minimum required: