I wrote a function based on Nizam Mohamed's answer. Please find the code here: https://github.com/ilario/replicate_object_python.
An usage example is reported here: https://stackoverflow.com/a/79539546/5033401 or in the readme of the repository.