Sunset offset condition in custom component

How should I check in Python for the sunset sensor with the offset condition which is available in YAML scripts?