SAN FRANCISCO — A California law allowing Uber and Lyft drivers to have a single business license to drive anywhere in the state is depriving San Francisco of fees that could offset maintenance and traffic costs created by ride-hailing services, San Francisco officials said in a lawsuit filed Thursday against the state.

The law signed by Gov. Jerry Brown last year prevents San Francisco from requiring drivers who live outside the city to pay for and obtain a local business license when driving in the city, City Attorney Dennis Herrera said. Herrera said nearly every other business owner who operates in San Francisco is required to obtain a local license.

“Uber and Lyft need to play by the same rules as every other business in San Francisco,” Herrera said in a statement. “Out-of-town drivers are choking our streets as their corporate overseers design ways to stiff city taxpayers when it comes to congestion, road repair and traffic safety costs.”

An email to Uber was not immediately returned. Lyft said in a statement that the law allows rideshare drivers to hold one “streamlined business license with predictable costs and reasonable privacy protections.” San Francisco business license rules create “serious safety and privacy concerns” for drivers because they require that drivers’ personal information is posted online, the company said.

The office of the state senator who authored the law, Steven Bradford D-Gardena, did not immediately have comment. Bradford’s office said in a news release in October that the law would reduce costs for drivers who often work in multiple cities and might otherwise be subject to a separate business license fee in each one.

The city filed the lawsuit in state court in San Francisco. The suit says the law violates the state constitution, and it seeks a court order blocking the measure.