I am trying to obtain the "Where from" extended file attribute which is located on the "get info" context-menu of a file in MacOS.
Example
When right-clicking on the file and displaying the info it shows the this metadata.
The highlighted part in the image below shows the information I want to obtain (the link of the website where the file was downloaded from).

I want to use this Mac-specific function using Python. I thought of using OS tools but couldn't figure out any.
TL;DR: Get the extended attribute like MacOS's "Where from" by e.g. pip-install
pyxattrand usexattr.getxattr("file.pdf", "com.apple.metadata:kMDItemWhereFroms").Extended Attributes on files
These extended file attributes like your "Where From" in MacOS (since 10.4) store metadata not interpreted by the filesystem. They exist for different operating systems.
using the command-line
You can also query them on the command-line with tools like:
exiftool:xattr(apparently MacOS also uses a Python-script)On MacOS many attributes are displayed in property-list format, thus use
-xoption to obtain hexadecimal output.using Python
Ture Pålsson pointed out the missing link keywords. Such common and appropriate terms are helpful to search Python Package Index (PyPi):
Search PyPi by keywords: extend file attributes, meta data:
xattrpyxattrosxmetadata, requires Python 3.7+, MacOS onlyFor example to list and get attributes use (adapted from pyxattr's official docs)
However you will have to convert the MacOS specific metadata which is stored in plist format, e.g. using
plistlib.File metadata on MacOS
Mac OS X 10.4 (Tiger) introduced Spotlight a system for extracting (or harvesting), storing, indexing, and querying metadata. It provides an integrated system-wide service for searching and indexing.
This metadata is stored as extended file attributes having keys prefixed with
com.apple.metadata:. The "Where from" attribute for example has the keycom.apple.metadata:kMDItemWhereFroms.using Python
Use osxmetadata to use similar functionality like in MacOS's
md*utils:See also