Yes you could, but (and it’s a big but): performance will be bad, performance for all other TOR users will be impeded, you won’t be able to open an incoming port, it’ll be a bad experience for everyone.
Additionally it’s quite easy to leak identifiable info in such a setup.
https://blog.torproject.org/bittorrent-over-tor-isnt-good-idea/
Did the same in python. Ages ago. And again in python half a decade ago. And again in python a few months ago.