A three-metre-long carpet python has attacked a six-year-old boy while he slept in the mid-New South Wales coastal town of Macksville.

The boy's mother Tammy woke to a "terrifying scream" and ran into the bedroom to find the snake wrapped around her son Tyler's belly.

"It was like a nightmare," she told the Nambucca Guardian News.

"I saw his face and the blood and his eyes were still closed so I don't think he was fully awake."

The boy had been bitten several times on his hands and face by the non-venomous python.

"I had to pull Tyler from the bed but he didn't come with me ... I had to roll him then pull," his mother said.

"I tried to check him over but he wouldn't let me touch him anywhere."

A spokeswoman for the mid-North Coast Local Health District told Fairfax the boy was admitted to Macksville District Hospital just after midnight on February 19, and was transferred to Coffs Harbour Hospital.

He was released later that morning and was said to be "fine" after the incident.

A family friend killed the snake soon after the boy was bitten.

Reptile expert Mark Sanders told the ABC the attack was incredibly rare and uncharacteristic of python behaviour.

"He must be the most unlucky kid alive," Mr Sanders said.

"They're not an aggressive animal. They're fairly reluctant to bite even when [provoked]. They hunt by smell and heat so maybe it sensed a bit of heat and struck out by mistake."

Studies have shown carpet python populations to be high in many urban areas, where they feed predominantly on small mammals such as rats and possums.

"They're so shy people don't realise they're there," Mr Sanders said.