Mayor Marion Barry, other District government officials, union leaders and the head of the city's Democratic Party endorsed legislation yesterday to exempt city government employes from the federal Hatch Act, which now prohibits them from engaging in political activities.

The only opposition to the legislation, presented at a congressional hearing yesterday, came from Ann F. Heuer, chairman of the city's small Republican Party, who charged that the change would leave city employes vulnerable to a municipal party machine.

The hearing was held by D.C. Del. Walter Fauntroy, chairman of the House District subcommittee on fiscal affairs, who introduced the bill. He said the legislation would be amended so that it would not apply to the current election year.

Barry, in a statement read for him, said lifting the federal restriction was a home rule issue.

"Under home rule, the local government should have the authority to determine whether or not these restrictions on government employes should be continued, modified or eliminated," he said.

Barry said the right to engage in partisan politics now is granted to most Maryland government employes, all Virginia government employes and government employes in at least 11 other states.

James M. Christian Sr., chairman of the D.C. Democratic State Committee, said the legislation would "set the stage for the adoption of legislation which would broaden the rights of employes to more fully participate in the process by which they are governed."