For Python there's Marshmallow (https://github.com/marshmallow-code/marshmallow) and Django REST Framework if you're using Django (http://www.django-rest-framework.org/api-guide/serializers/). Both of these work as you described.
Re:When Not to Serialize
by SamReidHughes on Saturday August 11, 2018 @10:14PM
(#17742590)
Serializers are just functions. Why do they need to be classes?
ActiveModel::Serializers work like this in Rails, although I haven’t tried any similar approaches in statically-typed languages where protobuf is so commonly used.