Library is quieter and better in terms of electric plugs and internet connection. Only downside is that it's closes pretty early. Only few days a week you can work till 7pm or 8pm. So it's perfect for a weekend. Main SF Library on Larkin is pretty good, has lots of light and open space. It has a restroom too. If you willing to tolerate commuting there, honestly outside looks sketch and always have something going on in there.
Coffee shops are better for a weekday. There might be troubles with wifi reliability or power outlets(there might not be), noise levels, people walking all the time.
I found out that I prefer to go to cafe Reveille. It's nice and clean and they have pretty decent wifi, though they don't have any electric outlets.
Another option is a Starbucks on Fillmore street. Main benefit being that it works until 9pm almost every day, and you can crank up few solid hours there after work