To police, he was a gang-banger with a gun. But to his school, he was a lovable 16-year-old who strove to be a better student by taking on extra work.

The Urban Assembly School of Design and Construction sent a letter to parents and staff today in honor of Kimani Gray — who was fatally shot by undercover cops last week after allegedly pulling a gun on them.

“We believed in his potential from the day he entered our school,” wrote principal Matt Willoughby. “He traveled for over an hour each day from East Flatbush to Midtown West to our little architectural themed high school. The year and a half we had with Kimani allowed us to get to know his best self.

“Kimani made great strides this year academically. He was taking an extra English class after school; he was writing a dramatic dialogue in another English class; his group in Design class was working on a project to design a school. Now they are working to complete their project without him.”

Gray, known as “Kiki” to friends and family, was a popular 10th-grader at the W. 50th Street school — where teachers were still mourning his death yesterday afternoon.

One teacher told The Post that staff wanted to write an editorial defending Gray against his criminal record, which includes grand larceny and inciting a riot.

“He always smiled, he came to school every day, and the kids here miss him,” the teacher said. “That says a lot.”

Another said Gray’s fellow students were devastated when told the news of the teen’s demise.

“When I shared this information with a classroom full of kids, they’re faces went grey. I could see the devastation. One kid immediately started crying when we told the class,” the teacher said. “Kimani was a kid who really got along with everybody. You were never not happy to see him.”

Willoughby wrote that it was important to share more about the student they knew.

“My hope is that as a community we can agree that the death of anyone so young is tragic,” he said. “Kimani should be remembered for all of who he was — an energetic, kind, playful, independent young man who was trying to learn and grow one day at a time.”

Gray, who police say was a member of the Bloods, was outside a party on E. 52nd Street in East Flatbush on March 9 when two plainclothes cops approached him. The officers shot him seven times after he allegedly pulled a revolver from his waistband.

If Gray was involved in a gang, a teacher said it never showed at school.

“Considering what it looks like he was going through outside of school, it’s amazing that he was coming to school every day, he was staying in dress code and he was coming after school,” the teacher said.