Serving as a cop in America is harder than ever — and it comes down to respect. A deficit of respect for the men and women in blue who daily put their lives on the line for the rest of us is hurting recruitment and retention and placing communities at risk.

This month, Sgt. Christopher Brewster of the Houston Police Department was shot and killed while responding to a domestic-violence call.

Several hours later that same day, Officer Stephen Carr of ­Arkansas’ Fayetteville Police ­Department was ambushed and executed while sitting in his patrol vehicle. Last week, Det. ­Joseph Seals was shot and killed by those who carried out the Jersey City massacre. Seals’ funeral is Tuesday.

There is no tougher job in the country than serving as a law-enforcement officer. Every morning, officers across the country get up, kiss their loved ones and put on their protective vests. They head out on patrol never knowing what threats and trials they will face. And their families endure restless nights, so we can sleep peacefully.

Policing is only getting harder. Police officers are now required to handle the fallout from a vast range of social ­pathologies that were once the domain of social workers, psychologists and family members, such as mental illness, widespread homelessness and drug abuse.

Even more demoralizing, police officers must look on as the criminals that they have risked their lives to apprehend get turned loose by “social-justice” DAs and “progressive” judges who no longer see their role as protecting the community from predators. Some DAs have even exposed police officers to greater danger by announcing that they will not prosecute those who resist police.

Increasingly, police officers find themselves the subject of physical attacks. Assaults against police jumped 20 percent from 2014 to 2017, up to about 60,000 a year.

While policing is demanding, it’s uniquely rewarding. Law ­enforcement is a noble calling, and we are fortunate that there are still men and women of character willing to serve selflessly so that their fellow citizens can live securely.

The fight against crime is perpetual. There is no final victory; the end is never in sight. To wage this struggle takes a special kind of fortitude. It takes its toll. Officers are at a higher risk of suicide than members of any other profession. The number of officer suicides is more than triple that of deaths in the line of duty.

We now live in a full-employment economy. There are many career options outside of law enforcement. As the demands being placed on police have ­become more intense, recruiting and retaining high-caliber officers have become a nationwide challenge.

In the last 20 years, the number of full-time sworn officers per capita dropped 11 percent. Departments are experiencing shortages. The number of applications has significantly decreased over the past several years, and many officers are leaving well before retirement age.

Here is the stark reality: Without a serious focus on officer ­retention and recruitment, ­including a renewed appreciation for our men and women in blue, there won’t be enough ­police officers to protect us.

There were times in the past when we didn’t demonstrate sufficient respect for men and women who served in our armed forces. Thankfully today, veterans and members of the military get the respect they ­deserve. There are demonstrations of gratitude when they ­deploy and return home, and even in everyday encounters, Americans thank them for their service. As a country, we need to do more to recognize the sacrifice and the service of law ­enforcement.

Support for officers, at a minimum, means adequate funding. It also means lending them an extra degree of goodwill for having chosen a trying life of public service.

Which is why the administration has made backing law ­enforcement a top priority. Among other initiatives, President Trump announced in ­October the formation of an ­executive commission to study key challenges facing law ­enforcement, the first such commission since the 1960s.

When we show our respect and appreciation for our police, it says more about our love of liberty and justice than perhaps any other act.

William Barr is the attorney general of the United States.