Servos often use potentiometers to measure the position. That works fine if you have a good quality potentiometer. A different alternative is to use an optical or mechanical decoder. You can find examples of 3D printed rotary encoders here:
It's made in two variants.
Natural encoded ( i.e. simply using binary form where a hole represents 1 and no hole = 0).
Gray code. Gray code has the advanage that only one bit changes for each step of the rotation.
If anyone want to test this type of encoder, I made two methods that can be used to convert from Gray code to decimal, and also from decimal to Gray.
It's based on this algorithm:
You can find an example Python script here: