Criminals broke into the systems of 17 libraries, disabled them and demanded a ransom.
It meant people were unable to borrow books or use the computers.
All services were being restored, said Waller McGuire, executive director of St Louis libraries, on Tuesday. No ransom has been paid to the attackers.
According to Intel Security, ransomware attacks are rising in “alarming” numbers.
Technical staff at the libraries across St Louis had been working “through the night and weekend” to regain access to the affected servers, using the library’s back-up system to restore them, Mr McGuire said in a statement.
Their first priority had been to restore the system that allowed books to be borrowed, which had now been done, he said.
Mr McGuire said: “St Louis Public Library has been working with the FBI to identify how criminals broke into our system and correct the problem.
“I apologise to patrons for any inconvenience this incident has caused: on most days thousands of St Louis Public Library patrons check out materials and use computers for many purposes.
“The real victims of this criminal attack are the library’s patrons.”
“An attempt to hold information and access to the world for ransom is deeply frightening and offensive to any public library, and we will make every effort to keep that world available to our patrons.”