What exactly do you mean by ‚generate‘?
TLEs are mainly used by NORAD, you can find a specification on their website, telling you what exactly any particiluar character of the TLE means. That will be helpful if you want to create your own.
If you just want to read TLEs for existing spacecraft, there is a big list on NORAD‘s website, where you can download any TLE for any tracked object.
There are quite a few python libraries for dealing with TLEs, using those you can just plug in a string and get SGP4 computed locations for any time in the future or past of the vessel.
I am not sure however if there is a python library for creating TLEs from orbital data, you will have to just do it yourself using the specification.