Two 12-year-old boys have been charged with the aggravated sexual assault of a female student at a primary school on Sydney's northern beaches.

The six-year-old girl reported the incidents herself, Fairfax Media has been told.

It is understood she was raped on two separate days at school in mid-August.

Both boys were allegedly present during both incidents but only one of the boys raped her in the second incident, police allege.

The primary school immediately notified the Department of Education, which immediately notified the NSW Police's Child Abuse Squad.