There are such things as private libraries (here's one in SF: http://www.milibrary.org/), and public libraries in other countries have different policies.
Municipal libraries often allow non-resident access for an annual membership fee.
University libraries are funded by tuition, and may allow non-university access for a fee.