If a police officer physically attacks you, with or without intent to arrest, can you legally defend yourself? Assume that the police officer punches/kicks/grabs first, and you are not guilty of any crime before the attack. To what extend can you do so?
The General Rule
In practice, the only time when self-defense against a police officer is legal is when you do not know and have no reasonable way that you could have known that the person attacking you is a police officer. (And arguably, a police officer acting in an official capacity in furtherance of his or her duties, rather than in a personal capacity as an individual.)
For example, if the police do a no knock raid in the dark of night, and don't announce themselves, and you shoot police officers reasonably believing them to be home invasion burglars, you would not have criminal or civil liability for doing so.
A similar valid self-defense claim might arise when someone has an objectively reasonable reason to think that someone claiming to be a police officer is really just a criminal impersonating a police officer, even if that belief is, in fact, mistaken.
In almost all other circumstances, you need to submit to the officers, and you are pretty much required by law to bear the risk that excessive force by the officer will harm you. If you don't, you will probably be guilty of the crime of resisting arrest and will not be entitled to a self-defense defense.
The fact that you are not actually guilty of a crime is irrelevant. This is often the case and police officers are not omniscient. If the officer lacked probable cause for an arrest (which there is often no way that the person being arrested or attacked can know at the time), the remedy is a civil rights suit after the fact, not self-defense.
In theory, there might be other isolated circumstances where self-defense against a police officer is legal, but they involve fact patterns so quirky that they would almost never happen in real life, or would almost never be possible to prove in a manner that the courts would believe.
Officer Liability For Harming Someone Legitimately Acting In Self Defense
Whether the officers had civil liability to you if you were harmed by the officers while exercising your right to self-defense would depend upon their state of mind, even if you were rightfully using self-defense.
For example, a U.S. Supreme Court case decided in January of 2017 (White v. Pauly) involved this fact pattern. In White v. Pauly an officer arrived late on the scene and had no reason to believe that the officers who arrived there before him and were being shot at by citizens in a house that they were approaching, lacked probable cause, or had not announced themselves. The court held that as a result, he had no civil liability to a citizen he shot, even if the person who the late arriving officer shot while that citizen was shooting back at the police officers on the scene was actually engaging in good faith self-defense.
The citizen's self-defense in the case had a valid defense to criminal or civil liability for firing on the officers, because the citizen shooting back didn't actually know that the people approaching his house were police officers. But, because the late arriving officer reasonably believed under the circumstances that the citizen had no right to engage in self-defense, because he thought that the early arriving officers had probable cause and had announced themselves, the late arriving officer had no civil liability to the citizens he shot.