Interesting that you bring this up. Just earlier this week I published the first version of a new package that lets you write compiled bytecode instructions inline with pure-Python syntax. The code's still a bit messy, being only a week old and all, but it works as advertised for CPython 3.6.2 through 3.9.0a0, and even includes neat features like labeled jumps, unused name/constant removal, stack size adjustments, etc... Perhaps it'll be useful to you (or at least you'll find it interesting): https://github.com/brandtbucher/hax
Victor's Stinner's Bytecode package (already mentioned) is surely better for *dynamic* generation... I've never used it personally, but it looks great.
Definitely not for the faint of heart, though! ;)