One should always aim for prevention in such cases i.e., doing AoP daily. Putting a strong AoP on yourself will prevent you from getting into a situation where you have to defend yourself physically.
Regarding physical self defense, always follow the law of the country you are residing in. Study the law and the past cases. See if just retaliation is frowned upon by the law or if it is legal. We abide by all the laws dictated by the state or the country. There are no spiritual laws dictated by any country or state, yet. As such, you are free to retaliate spiritually if someone has gravely offended you. However, this does not mean that you can go on committing injustices against the innocent.
Note that this is only for cases where there is no physical altercation i.e., you cannot immediately defend yourself spiritually if someone wants to harm you physically. In that case, learn weapons and firearms laws of the country or the state that you are residing in.
If you are reside in an area where you have to worry about physically protecting yourself, move out asap.
Search for a safe place to live all the while you put a strong AoP on yourself. Moving out is of utmost importance if you reside in such a dangerous area even with an AoP.