The incident comes after two mass shootings in the US earlier this month. (AFP)

Six police officers were shot and wounded in the US city of Philadelphia on Wednesday during an hours-long incident that began when police tried to execute a narcotics warrant, the Philadelphia Police Department said.

All of the officers were later released from hospital, but police Commissioner Richard Ross Jr said that in 30 years he had never seen so many officers shot over such a long period of time.

The incident comes after two mass shootings in the US earlier this month -- one in Dayton, Ohio and the other in El Paso -- left a total of 31 people dead.

Two other officers who had been trapped in a house with the suspected Philadelphia shooter were finally freed later in the evening, Ross said during a press conference.

"Right now we have gone from a hostage situation to a barricade," with the gunman still holed up, he said.

Late Wednesday officers were focused on convincing the suspect to come out of the house peacefully and Ross said he seemed to have stopped shooting.

"We've called him multiple times," the commissioner said earlier.

The suspect had been firing out of the window, he said, and officers initially shot back.

Department spokesman Sergeant Eric Gripp had first tweeted about the incident hours earlier, around 4:40 pm local time (20:40 GMT), and continued to advise the public to stay away from the area throughout the evening.

"It is nothing short of astounding that in such a confined space that we didn't have more of a tragedy than we did," Ross said.

The episode began as an attempt to execute a narcotics warrant "that went awry almost immediately," he explained.

Philadelphia Mayor Jim Kenney praised his city's police department but called out federal and state politicians for their response to gun violence.

"This government, both federal and state level, don't want to do anything about getting guns off the street," he said at a press conference.

"Our officers deserve to be protected and don't deserve to be shot at by a guy for hours with unlimited amount of bullets. It's disgusting. We need to do something about it."

Despite rampant gun violence in the United States, efforts to strengthen firearms regulations remain divisive in the country, where the powerful National Rifle Association works to block stricter rules.