Any epi with codomain $P$ is split implies $P$ is projective I'm struggling to prove that if any epi with codomain $P$ splits, then $P$ is a projective object. The converse direction I proved by factoring the identity to give a right inverse of the pi.
How can I prove this claim?
 A: Here is a counterexample: Consider the category with three objects $P$, $X$ and $Y$, and two non-identity morphisms $f : P \to X$ and $\pi : Y \to X$ (and the only possible composition rules). Then every epimorphism with codomain $P$ splits (there is only one such epimorphism, the identity...). But $P$ is not projective: $\pi$ is an epimorphism, but $f$ does not factor through $\pi$.

Wrong answer below!
I'm pretty sure that you mean "any epi with codomain $P$ splits". Compare with the case of projective modules over a ring: exact sequences $0 \to A \to B \to P \to 0$ split when $P$ is projective. And for example $\mathbb{Z} \twoheadrightarrow \mathbb{Z}/2\mathbb{Z}$ doesn't split even though $\mathbb{Z}$ is projective in the category of abelian groups.
Let $f : P \to X$ be a morphism, and $\pi : Y \to X$ an epimorphism. Take the pullback:
$$\require{AMScd}
\begin{CD}
Y \times_X P @>{f'}>> Y \\
@V{\pi'}VV @V{\pi}VV \\
P @>{f}>> X
\end{CD}$$
Then since epimorphisms are stable under pullbacks (They are not! this argument is wrong.), the projection $\pi' : Y \times_X P \to P$ is epimorphic. By hypothesis it splits, so let $s : P \to P \times_X Y$ be a splitting, ie. $\pi' \circ s = \operatorname{id}_P$. Let $g = f' \circ s : P \to Y$. Then $\pi \circ g = \pi \circ f' \circ s = f \circ \pi' \circ s = f$ and so $f$ factors through $\pi$.

Note: this assumes that pullbacks exist in the category we are considering (generally they do in homological algebra, but one has to be careful). Otherwise the claim is false. (Edit: And the argument is wrong anyway!)
