Every integer above 1 is a unique product of primes (the Fundamental Theorem of Arithmetic). To find them, divide out the smallest factor repeatedly:
d = 2
while d * d <= n:
while n % d == 0:
factors.append(d); n //= d
d += 1
if n > 1: factors.append(n) # leftover prime
You don't need to check that d is prime. By the time you reach a composite d, its prime factors have already been divided out. The leftover n > 1 at the end must itself be prime.