I am assuming that you are allowing for repetitions, unlike the suggested duplicate answers although really the idea is the same. You can use recursion as follows (or recursive generator instead):
def sum_to(num, parts):
if num == 0:
return [[]]
return [[x, *lst] for x in parts if x <= num for lst in sum_to(num - x, parts)]
output = sum_to(6, [1, 2, 3])
print(len(output))
print(output)
Output:
24
[[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 2], [1, 1, 1, 2, 1], [1, 1, 1, 3], [1, 1, 2, 1, 1], [1, 1, 2, 2], [1, 1, 3, 1], [1, 2, 1, 1, 1], [1, 2, 1, 2], [1, 2, 2, 1], [1, 2, 3], [1, 3, 1, 1], [1, 3, 2], [2, 1, 1, 1, 1], [2, 1, 1, 2], [2, 1, 2, 1], [2, 1, 3], [2, 2, 1, 1], [2, 2, 2], [2, 3, 1], [3, 1, 1, 1], [3, 1, 2], [3, 2, 1], [3, 3]]