This week, one of the many repeat offenders allowed to walk our streets unleashed a barrage of bullets on Philadelphia police officers.

What started as the execution of a narcotics warrant turned into a seven-hour standoff punctuated by shootouts that left six officers wounded. While many Americans were glued to their televisions or phones awaiting the outcome, some who had gathered near the scene in Philly’s (not-so) Nicetown neighborhood taunted and laughed at the officers whose colleagues had just been wounded.

It was just the latest sign of disrespect for the police and the mounting disorder that accompanies it.

Just days earlier, in The Bronx, a rowdy crowd swarmed NYPD officers while they were attempting to make an arrest. Now-viral cellphone video captured one officer being pelted with an open container of Chinese takeout. That was preceded by two separate incidents — both captured on video — in which NYPD officers were doused with water, cursed at and assaulted in Brooklyn and Harlem.

Unfortunately, such disdain for the police isn’t just confined to rowdy crowds in bad neighborhoods — there’s an institutional element to it. “Progressive” leaders in cities across the country have been contributing to a culture of disrespect for police for some time now, and it’s starting to show.

Take, for example, news of ThriveNYC’s recent snub of the pro-police organization Blue Lives Matter. According to City Councilman Joe Borelli, Thrive — a billion-dollar program headed by Mayor de Blasio’s wife, Chirlane McCray — pulled its offer to participate in a mental-health awareness event for first responders because it was being cosponsored by the pro-police group.

Borelli told The Post that the event was canceled “because of the PC environment that de Blasio has caused.”

Mind you, all of this went on in the middle of a sharp uptick in the number of NYPD suicides (seven since June of this year, compared to an annual average between four and five).

Given the mayor’s history of anti-police rhetoric, it’s not hard to imagine why some city worker somewhere might not like the idea of cosponsoring an event with a pro-police group — even a mental-health event for members of a police department whose officers have been committing suicide at alarming rates.

Speaking on ABC’s “This Week” in 2014, Hizzoner endorsed the view that parents “who have children of color” should “train them to be very careful when they have . . . an encounter with a police officer.” This prompted police to turn their backs on the mayor after two officers were shot and killed that same year.

Last month, de Blasio’s son, Dante, told readers in USA Today that “young black people” are taught (as he was) “to fear the people meant to protect us.”

The disdain shown toward the officers in Philly isn’t all that far removed from that city’s leadership, either. As US Attorney William McSwain of Pennsylvania’s Eastern District pointed out in a recent statement, this “new culture of disrespect for law enforcement . . . is promoted and championed by District Attorney Larry Krasner.”

Krasner has been a harsh critic of the criminal-justice system and campaigned on a platform of radical reforms. McSwain’s statement pointed to the DA’s victory party, which featured chants of “F - - k the police” and “No good cops in a racist system.”

There is a growing tension between the public and police — particularly in cities headed by “progressives” like Krasner and de Blasio.

That is not good for police morale; and it could have negative implications for the public’s safety as well. We’ve seen what happens when police departments back off and become less proactive.

In Chicago, one study suggested the sharp drop-off in police stops led to an additional 239 murders and over 1,100 more shootings in 2016 — a year in which Windy City homicides jumped 58 percent. The police back-off in Baltimore has also been well-documented, as crime continues to rise in that benighted city.

Police all around the country have been given a bum rap, and a growing portion of the public is buying into it. Simply put, police are an integral part of any functioning city.

We alienate them at our peril — and everyone else’s.

Rafael Mangual is a fellow and deputy director of legal policy at the Manhattan Institute.