dictmapperMaps hierarchical dictionaries to flat structures | |
Download |
dictmapper Ranking & Summary
Advertisement
- License:
- MIT/X Consortium Lic...
- Price:
- FREE
- Publisher Name:
- Reshef Mann
- Publisher web site:
- http://reshefmann.com
dictmapper Tags
dictmapper Description
dictmapper is a Python module created to help transforming a sequence of Python dictionaries to tabular format and specifically to transform JSON documents to be exported in CSV fromat.UsageCreate a mapper:from dictmapper import Mapper, Mappingclass UserMapper(Mapper): user_id = Mapping('user_id') email = Mapping('email') Name = Mapping(lambda u: '%s %s' % (u, u), name='User Name') nickname = Mapping('nickname', default='N/A') street = Mapping('address/street') city = Mapping('address/city') joined_at = Mapping('joined_at', transform=lambda d: d.strftime('%Y-%m-%d'))Sample input:users_docs = Output:>>> mapper = UserMapper()>>> mapper.headers()>>> res = mapper.map(users_docs)>>> res, ]Export to csvI recommend using the excellent tablib:import tablibdata = tablib.Dataset(*res, headers=mapper.headers())data.csvProduct's homepage
dictmapper Related Software