You really do not need some arguments like optional
, because with string types it not have sense. My simplified example:
class StateMatcher(dict):
def best_match(self, obj):
for state, params in sorted(self.items(),
key=lambda item: len(item[1]),
reverse=True):
for param in params:
if param not in obj:
break
else:
return state
return None
sm = StateMatcher([
('state1', ['name']),
('state2', ['name', 'address']),
])
state = sm.best_match(request.args)
If you need you always can make own builder to build right structure for check. If you need smart algorithm to get best match you must implement it yourself. If you need more complex properties with type validation and etc you can try wrap something like jsonscheme.