Yes I think the API above would be perfectly fine as a helper to convert a SCVal to it's Python type. Though I would see this more as a class method (and change the name then to something like to_python_type or dump or something else a bit more descriptive). i.e. something similar to what you have in Pandas or NumPy with tolist (but with an underscore).
As it is, it's a bit complicated for users because the names are a bit different than the type.
The context is that from an event I get two topics and a value.
topic_a = 'AAAADwAAAAZjb21taXQAAA=='
topic_b = 'AAAADQAAACCa/N5K2SsdROdFe/OAy7D47x6z81F+57cvQ763w7wCrA=='
value = 'AAAADQAAABTF7kUFjfiSWLEGkJ0tlC0w0SMASA=='
So I do
topic_a_scval = stellar_sdk.xdr.SCVal.from_xdr(topic_a)
topic_a_str = stellar_sdk.scval.from_symbol(topic_a_scval)
topic_b_scval = stellar_sdk.xdr.SCVal.from_xdr(topic_b)
topic_b_bytes = stellar_sdk.scval.from_bytes(topic_b_scval)
binascii.b2a_hex(topic_b_bytes)
value_scval = stellar_sdk.xdr.SCVal.from_xdr(value)
value_bytes = stellar_sdk.scval.from_bytes(value_scval)
binascii.b2a_hex(value_bytes)
So yeah for now I can do this
topic_a_scval = stellar_sdk.xdr.SCVal.from_xdr(topic_a)
type_name = topic_a_scval.type.name.split('_')[1].lower()
getattr(stellar_sdk.scval, f"from_{type_name}")(topic_a_scval)
But that's a bit hard on users IMO. I am happy to make a PR to propose this function if you would like.
For __str__, yes I would want to have __repr__. If you have __repr__ Python default to it for __str__ , this is why I was suggesting to just change str to repr as a "quick fix". Happy to read that you will add that to the next version! ๐