Harlem Rep. Charles Rangel is giving the teachers union a lesson in political retribution for snubbing him and endorsing his rival Adriano Espaillat for Congress, sources said.

Rangel is hitting the union where it hurts — by vigorously supporting non-unionized charter schools. The unions have been fighting desperately to stop or slow down charter-school expansion.

“The congressman was disappointed the UFT [United Federation of Teachers] dumped him for Espaillat. I see Charlie speaking out more forcefully on the charter-school issue,” said a Rangel ­insider.

“He doesn’t have to be concerned about offending the union. Charlie can let it rip.”

The UFT abandoned Rangel, a 22-term incumbent, and endorsed Espaillat on May 7.

Two days later, Rangel voted for the “Empowering Parents Through Quality Charter Schools Act” in the House of Representatives to fund charter expansion.

Then on June 23, the day before the Democratic primary, Rangel showed up as the surprise commencement speaker at the Harlem Link Charter School graduation ceremony. The staff there does not belong to the union.

Charter supporters described Rangel as having been only “lukewarm” on charters previously.

But advocates are thrilled with the possibility that Rangel — who claims he will retire in two years and is unburdened by any political debt to the union — will be an aggressive booster in his final term.

He doesn’t have to be concerned about offending the union. Charlie can let it rip. - A Rangel insider

“I was pleasantly surprised that he showed up at Harlem Link,” said Charles Taylor, whose son, Fernando, attends the school. “The congressman’s going for broke.”

Rangel said closing the achievement gap between minority and white students is a civil-rights ­issue and that charters are part of the solution.

“Harlem Link is part of a wave of charter schools that opened in the last decade in New York City with the intention of providing academic opportunities for families across income levels and proving that demography is not destiny,” a Rangel statement said.

The release said Harlem Link “has consistently outperformed other schools throughout the city on state exams” since 2008.

“Being successful is never easy,” Rangel told the students. “But by attending a school such as this, you put yourself at an advantage.”

Asked about Rangel’s blossoming charter love, spokeswoman Hannah Kim said he “has been consistent in his belief that the ­focus should be not on the system, but on the students and equipping the teachers with adequate tools.”

Rangel knows that backing charter schools is good politics as well as good policy. There are more than two dozen charter schools in his 13th Congressional District that takes in northern
Manhattan and parts of The Bronx — more than any other district in the city.