The attack was reported at about 9:55 p.m. Tuesday in the 300 block of London Street.
As the victim arrived at her home and was closing her front gate, two male suspects pushed their way in, according to police.
One of the suspects, described as a man in his mid-30s, then took out a handgun and struck the woman in the head with it, police said.
The woman screamed, causing the suspects to flee. They had not been found as of today, according to police.
The woman was taken to San Francisco General Hospital to be treated for her injuries, which are not considered life-threatening.
Anyone with information about the attack is encouraged to call the Police Department's anonymous tip line at (415) 575-4444 or send a tip by text message to TIP411.