Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

San Francisco asked a federal judge Friday to block enforcement of a Trump executive order that would cut off federal money to sanctuary cities — local governments that limit police cooperation with federal immigration authorities.

Joined by nearby Santa Clara county, the city argued that the president has no power to withhold federal funds without approval from Congress. And complying with the executive order, San Francisco said, would violate the constitutional rights of prisoners.

The city and county are asking Judge William Orrick to issue a nationwide injunction blocking the order. He did not immediately rule on the request.

The Trump administration argued that the lawsuit, and the request for an order blocking enforcement of the executive order, are premature because the government hasn't yet taken steps to carry it out.

The city said it could lose about $2 billion a year in federal funds, but a Justice Department lawyer told the judge that only a much smaller amount of grant money could be withheld if the city fails to comply.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Related: Conservative Cities See ‘Sanctuary City’ Term as Scarlet Letter

At the heart of the dispute are detainer requests, issued by U.S. Immigration and Customs Enforcement or ICE, asking local police and sheriff's offices to hold jail inmates for up to 48 hours after they have completed serving their sentences.

The requests apply to people here illegally who are convicted of committing local crimes. They could be deported after they are released.

City ordinances prohibit San Francisco police from giving immigration authorities advance notice of an inmate's release from jail, even if the police know that ICE wants to detain that person.

Related: ICE Suspends Weekly ‘Sanctuary City’ Report Over Accuracy Concerns

Complying with detainer requests is voluntary, the city argued, and local authorities believe the city is better off when residents to not view its police force as an arm of federal immigration agencies.

Protesters shout and hold up signs at San Francisco International Airport in San Francisco, California on January 29, 2017. US President Donald Trump issued an executive order yesterday barring citizens of seven Muslim-majority countries from entering the United States for the next 90 days and suspends the admission of all refugees for 120 days. JOSH EDELSON / AFP - Getty Images

"San Francisco is safer when all people, including undocumented immigrants, feel safe reporting crimes," its lawyers said. And they said holding an inmate after a jail sentence has been served could subject the city to lawsuits over unconstitutional detention.

They also said President Trump has no authority to issue orders to local law enforcement or to withhold federal money on his own. "Any restriction on eligibility for federal funds must be imposed — clearly, unambiguously, and in advance — by Congress," city lawyers said in their written briefs.

But Justice Department lawyers said the lawsuit should be thrown out, because the administration hasn't taken any action against the city or Santa Clara county.

"San Francisco does not claim the loss of any federal funds or, for that matter, contend that any action has been taken against it. The city does not even allege that such action has been threatened," government lawyers said.

Attorney General Jeff Sessions speaks at a news conference at the Justice Department in Washington on March 2, 2017. Yuri Gripas / Reuters

President Trump has repeatedly said that the actions of sanctuary cities allow dangerous criminals back on the street. His executive order also directed the Department of Homeland Security to regularly publish lists of local governments that fail to comply with detainers, but that effort has been suspended after the first list contained a number of errors.

Other lawsuits against the sanctuary city directive are pending, filed by cities in Massachusetts, Washington, and elsewhere in California.