Conditional density estimation tools in python and R with applications to photometric redshifts and likelihood-free cosmological inference