README.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. Tablib: format-agnostic tabular dataset library
  2. ===============================================
  3. ::
  4. _____ ______ ___________ ______
  5. __ /_______ ____ /_ ___ /___(_)___ /_
  6. _ __/_ __ `/__ __ \__ / __ / __ __ \
  7. / /_ / /_/ / _ /_/ /_ / _ / _ /_/ /
  8. \__/ \__,_/ /_.___/ /_/ /_/ /_.___/
  9. Tablib is a format-agnostic tabular dataset library, written in Python.
  10. Output formats supported:
  11. - Excel (Sets + Books)
  12. - JSON (Sets + Books)
  13. - YAML (Sets + Books)
  14. - HTML (Sets)
  15. - TSV (Sets)
  16. - CSV (Sets)
  17. Note that tablib *purposefully* excludes XML support. It always will. (Note: This is a joke. Pull requests are welcome.)
  18. Overview
  19. --------
  20. `tablib.Dataset()`
  21. A Dataset is a table of tabular data. It may or may not have a header row. They can be build and manipulated as raw Python datatypes (Lists of tuples|dictionaries). Datasets can be imported from JSON, YAML, and CSV; they can be exported to XLSX, XLS, ODS, JSON, YAML, CSV, TSV, and HTML.
  22. `tablib.Databook()`
  23. A Databook is a set of Datasets. The most common form of a Databook is an Excel file with multiple spreadsheets. Databooks can be imported from JSON and YAML; they can be exported to XLSX, XLS, ODS, JSON, and YAML.
  24. Usage
  25. -----
  26. Populate fresh data files: ::
  27. headers = ('first_name', 'last_name')
  28. data = [
  29. ('John', 'Adams'),
  30. ('George', 'Washington')
  31. ]
  32. data = tablib.Dataset(*data, headers=headers)
  33. Intelligently add new rows: ::
  34. >>> data.append(('Henry', 'Ford'))
  35. Intelligently add new columns: ::
  36. >>> data.append_col((90, 67, 83), header='age')
  37. Slice rows: ::
  38. >>> print data[:2]
  39. [('John', 'Adams', 90), ('George', 'Washington', 67)]
  40. Slice columns by header: ::
  41. >>> print data['first_name']
  42. ['John', 'George', 'Henry']
  43. Easily delete rows: ::
  44. >>> del data[1]
  45. Exports
  46. -------
  47. Drumroll please...........
  48. JSON!
  49. +++++
  50. ::
  51. >>> print data.json
  52. [
  53. {
  54. "last_name": "Adams",
  55. "age": 90,
  56. "first_name": "John"
  57. },
  58. {
  59. "last_name": "Ford",
  60. "age": 83,
  61. "first_name": "Henry"
  62. }
  63. ]
  64. YAML!
  65. +++++
  66. ::
  67. >>> print data.yaml
  68. - {age: 90, first_name: John, last_name: Adams}
  69. - {age: 83, first_name: Henry, last_name: Ford}
  70. CSV...
  71. ++++++
  72. ::
  73. >>> print data.csv
  74. first_name,last_name,age
  75. John,Adams,90
  76. Henry,Ford,83
  77. EXCEL!
  78. ++++++
  79. ::
  80. >>> with open('people.xls', 'wb') as f:
  81. ... f.write(data.xls)
  82. It's that easy.
  83. Installation
  84. ------------
  85. To install tablib, simply: ::
  86. $ pip install tablib
  87. Or, if you absolutely must: ::
  88. $ easy_install tablib
  89. Contribute
  90. ----------
  91. If you'd like to contribute, simply fork `the repository`_, commit your
  92. changes to the **develop** branch (or branch off of it), and send a pull
  93. request. Make sure you add yourself to AUTHORS_.
  94. .. _`the repository`: http://github.com/kennethreitz/tablib
  95. .. _AUTHORS: http://github.com/kennethreitz/tablib/blob/master/AUTHORS