register it with systemd, monit or runit. these are service managers who, when the programs they are watching die, note its absence and restart it with the command line mechanism you’ve provided. might be a bit tricky to get your head around them (and provide the pid or other scheme to “sign” a python script’s presence) but it’s what they’re designed to do. I am quite fond of runit myself but systemd is (perhaps unfortunately) present on most Linux distributions.
other stuff you rely on, not just your script, may also need similar overwatch, though typically things like database servers already configure themselves to do this from the start.
Past ensuring good coding hygiene, quality and testing, addressing your type of requirement in any program itself (in Python or other languages) is an unproductive and falsely reassuring pursuit. High availability mechanisms rely on worker/master or sibling systems where a second program restarts the first. Not on “hoping for the best” from your own programming skills.
This, as @Ondrej K also said, is best left to your distro - init is another framework dedicated to this. Five months of uptime is a totally reasonable expectation from a well-configured Linux system. And, as he pointed out, these mechanisms also cover system reboots.
Just to be clear: you still need to ensure your program can handle itself under all circumstances - cycling restarts won’t help if it’s stuck on a write permission error for example.
P.S. if the Pi’s networked, ssh might be helpful if you need to access it.