Package: ffmetadata-py
ffmetadata-pyPython wrapper for Fragile Families Metadata APIThis Python package provides convenient wrappers to interface with theFragile Families Metadata API. By downloading and importing theffmodule, users can query the metadata variables. No other software installation is necessary.RequirementsTheffmodule has been tested on Python 3.6, and should work on most Python 3.x installations.InstallationTheffmetadata-pypackage isavailable on The Python Package Index (PyPI). The easiest way to install and use the module is to do apip installpip install ffmetadata-pyThis step will also install any dependencies if needed (currently, therequestsandsimplejsonlibraries).Alternatively, you can clone this Github repository and place thefffolder and it's contents at a location accessible by your Python 3.x installation (most commonly thesite-packagesfolder for your Python installation). In this scenario, make sure that you have recent versions of therequestsandsimplejsonlibraries installed.Getting StartedTo get started, import the ff module usingimport ff. Follow the examples below on how to use the library.ExamplesGetting attributes of a variableGetallattributes of a variableGiven the variable name, this function call returns a dictionary of all attribute name/value pairs.>>> ff.select('ce3datey')
{'data_source': 'constructed', 'data_type': 'Continuous', ...Get a single attribute of a variableTo get a single attribute value, call theselectfunction with the second argument as the attribute you're interested in. Most attributes returnstrvalues, but a handful haveintreturn values.>>> ff.select('ce3datey', 'data_source')
'constructed'Get multiple attributes of a variableTo get multiple attribute values, call theselectfunction with the second argument as a list of string attribute names. A dictionary with name/value pairs is returned.>>> ff.select('ce3datey', ['name', 'data_source'])
{'data_source': 'constructed', 'name': 'ce3datey'}Searching for variablesQuerying variables is done using thesearchfunction. In the simplest case, this function expects a dictionary with keysname,opandval. In all cases, a list of variable names is returned. Some examples follow.Find variable(s) where name='ce3datey'>>> ff.search({'name': 'name', 'op': 'eq', 'val': 'ce3datey'})
['ce3datey']Find variable(s) where data_source='constructed' AND name ends with 'e'Multiple search criteria can be specified by passing in a list of dictionaries. These are combined with anANDclause.>>> ff.search([{'name': 'data_source', 'op': 'eq', 'val': 'constructed'}, {'name': 'name', 'op': 'like', 'val': '%e'}])
['cf1age', 'cf1ethrace', ...Find variable(s) where data_source='constructed' OR name starts with 'c' OR name ends with 'd'To specify anORclause for multiple search combination, replace the search criteria with a dictionary keyed byOR, with values as a list of dictionaries.>>> ff.search({'or': [{'name': 'data_source', 'op': 'eq', 'val': 'constructed'}, {'name': 'name', 'op': 'like', 'val': 'c%'}, {'name': 'name', 'op': 'like', 'val': '%d'}]})
['cf1intmon', 'cf1intyr', ...Find variable(s) where data_source='constructed' OR (name ends with 'f' AND data_source='questionnaire')More complicated search queries can b constructed, by combining several AND/OR clauses. In such cases, at any point where you want to specify a sub-query, pass in a dictionary keyed by either anANDorOR, with the values being valid search criteria themselves - either dictionaries of name/op/val keys, or sub-queries (defined recursively).>>> ff.search({'or': [{'name': 'data_source', 'op': 'eq', 'val': 'constructed'}, {'and': [{'name': 'name', 'op': 'like', 'val': '%f'}, {'name': 'data_source', 'op': 'eq', 'val': 'questionnaire'}]}]})
['cf1intmon', 'cf1intyr', ...For more complicated search queries, you may find the interactiveAdvanced Searchpage on the project website useful.