This is a gate latch for a fairly common style baby or pet gate that is sold on Amazon under many different names. I have purchased different brands with identical latch styles. Look up ASIN B09X1DG9B5 or ASIN B0B3R5Y16M to see if this is similar to yours.
The stock gate latch has a plastic catch that retains the latch pieces in place. My original latch went flying when the retention catch broke. The outer part is all I needed, but I wanted to also design the inner pieces as well, in case yours went flying like mine. I eventually found the inside piece and spring intact, but this one includes a printable plastic spring that can be used. You can also break the spring out and just use your own metal spring. But worst case, you can print this 100% and use it from day 1.
I did my best to design this with minimal supports and to completely avoid supports needing to be removed from the PLA spring.
This is my original latch design, built from scratch.