You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

256 lines
7.0KB

  1. Metadata-Version: 2.1
  2. Name: toml
  3. Version: 0.10.2
  4. Summary: Python Library for Tom's Obvious, Minimal Language
  5. Home-page: https://github.com/uiri/toml
  6. Author: William Pearson
  7. Author-email: uiri@xqz.ca
  8. License: MIT
  9. Platform: UNKNOWN
  10. Classifier: Development Status :: 5 - Production/Stable
  11. Classifier: Intended Audience :: Developers
  12. Classifier: License :: OSI Approved :: MIT License
  13. Classifier: Operating System :: OS Independent
  14. Classifier: Programming Language :: Python
  15. Classifier: Programming Language :: Python :: 2
  16. Classifier: Programming Language :: Python :: 2.6
  17. Classifier: Programming Language :: Python :: 2.7
  18. Classifier: Programming Language :: Python :: 3
  19. Classifier: Programming Language :: Python :: 3.3
  20. Classifier: Programming Language :: Python :: 3.4
  21. Classifier: Programming Language :: Python :: 3.5
  22. Classifier: Programming Language :: Python :: 3.6
  23. Classifier: Programming Language :: Python :: 3.7
  24. Classifier: Programming Language :: Python :: 3.8
  25. Classifier: Programming Language :: Python :: 3.9
  26. Classifier: Programming Language :: Python :: Implementation :: CPython
  27. Classifier: Programming Language :: Python :: Implementation :: PyPy
  28. Requires-Python: >=2.6, !=3.0.*, !=3.1.*, !=3.2.*
  29. ****
  30. TOML
  31. ****
  32. .. image:: https://img.shields.io/pypi/v/toml
  33. :target: https://pypi.org/project/toml/
  34. .. image:: https://travis-ci.org/uiri/toml.svg?branch=master
  35. :target: https://travis-ci.org/uiri/toml
  36. .. image:: https://img.shields.io/pypi/pyversions/toml.svg
  37. :target: https://pypi.org/project/toml/
  38. A Python library for parsing and creating `TOML <https://en.wikipedia.org/wiki/TOML>`_.
  39. The module passes `the TOML test suite <https://github.com/BurntSushi/toml-test>`_.
  40. See also:
  41. * `The TOML Standard <https://github.com/toml-lang/toml>`_
  42. * `The currently supported TOML specification <https://github.com/toml-lang/toml/blob/v0.5.0/README.md>`_
  43. Installation
  44. ============
  45. To install the latest release on `PyPI <https://pypi.org/project/toml/>`_,
  46. simply run:
  47. ::
  48. pip install toml
  49. Or to install the latest development version, run:
  50. ::
  51. git clone https://github.com/uiri/toml.git
  52. cd toml
  53. python setup.py install
  54. Quick Tutorial
  55. ==============
  56. *toml.loads* takes in a string containing standard TOML-formatted data and
  57. returns a dictionary containing the parsed data.
  58. .. code:: pycon
  59. >>> import toml
  60. >>> toml_string = """
  61. ... # This is a TOML document.
  62. ...
  63. ... title = "TOML Example"
  64. ...
  65. ... [owner]
  66. ... name = "Tom Preston-Werner"
  67. ... dob = 1979-05-27T07:32:00-08:00 # First class dates
  68. ...
  69. ... [database]
  70. ... server = "192.168.1.1"
  71. ... ports = [ 8001, 8001, 8002 ]
  72. ... connection_max = 5000
  73. ... enabled = true
  74. ...
  75. ... [servers]
  76. ...
  77. ... # Indentation (tabs and/or spaces) is allowed but not required
  78. ... [servers.alpha]
  79. ... ip = "10.0.0.1"
  80. ... dc = "eqdc10"
  81. ...
  82. ... [servers.beta]
  83. ... ip = "10.0.0.2"
  84. ... dc = "eqdc10"
  85. ...
  86. ... [clients]
  87. ... data = [ ["gamma", "delta"], [1, 2] ]
  88. ...
  89. ... # Line breaks are OK when inside arrays
  90. ... hosts = [
  91. ... "alpha",
  92. ... "omega"
  93. ... ]
  94. ... """
  95. >>> parsed_toml = toml.loads(toml_string)
  96. *toml.dumps* takes a dictionary and returns a string containing the
  97. corresponding TOML-formatted data.
  98. .. code:: pycon
  99. >>> new_toml_string = toml.dumps(parsed_toml)
  100. >>> print(new_toml_string)
  101. title = "TOML Example"
  102. [owner]
  103. name = "Tom Preston-Werner"
  104. dob = 1979-05-27T07:32:00Z
  105. [database]
  106. server = "192.168.1.1"
  107. ports = [ 8001, 8001, 8002,]
  108. connection_max = 5000
  109. enabled = true
  110. [clients]
  111. data = [ [ "gamma", "delta",], [ 1, 2,],]
  112. hosts = [ "alpha", "omega",]
  113. [servers.alpha]
  114. ip = "10.0.0.1"
  115. dc = "eqdc10"
  116. [servers.beta]
  117. ip = "10.0.0.2"
  118. dc = "eqdc10"
  119. *toml.dump* takes a dictionary and a file descriptor and returns a string containing the
  120. corresponding TOML-formatted data.
  121. .. code:: pycon
  122. >>> with open('new_toml_file.toml', 'w') as f:
  123. ... new_toml_string = toml.dump(parsed_toml, f)
  124. >>> print(new_toml_string)
  125. title = "TOML Example"
  126. [owner]
  127. name = "Tom Preston-Werner"
  128. dob = 1979-05-27T07:32:00Z
  129. [database]
  130. server = "192.168.1.1"
  131. ports = [ 8001, 8001, 8002,]
  132. connection_max = 5000
  133. enabled = true
  134. [clients]
  135. data = [ [ "gamma", "delta",], [ 1, 2,],]
  136. hosts = [ "alpha", "omega",]
  137. [servers.alpha]
  138. ip = "10.0.0.1"
  139. dc = "eqdc10"
  140. [servers.beta]
  141. ip = "10.0.0.2"
  142. dc = "eqdc10"
  143. For more functions, view the API Reference below.
  144. Note
  145. ----
  146. For Numpy users, by default the data types ``np.floatX`` will not be translated to floats by toml, but will instead be encoded as strings. To get around this, specify the ``TomlNumpyEncoder`` when saving your data.
  147. .. code:: pycon
  148. >>> import toml
  149. >>> import numpy as np
  150. >>> a = np.arange(0, 10, dtype=np.double)
  151. >>> output = {'a': a}
  152. >>> toml.dumps(output)
  153. 'a = [ "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "9.0",]\n'
  154. >>> toml.dumps(output, encoder=toml.TomlNumpyEncoder())
  155. 'a = [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0,]\n'
  156. API Reference
  157. =============
  158. ``toml.load(f, _dict=dict)``
  159. Parse a file or a list of files as TOML and return a dictionary.
  160. :Args:
  161. * ``f``: A path to a file, list of filepaths (to be read into single
  162. object) or a file descriptor
  163. * ``_dict``: The class of the dictionary object to be returned
  164. :Returns:
  165. A dictionary (or object ``_dict``) containing parsed TOML data
  166. :Raises:
  167. * ``TypeError``: When ``f`` is an invalid type or is a list containing
  168. invalid types
  169. * ``TomlDecodeError``: When an error occurs while decoding the file(s)
  170. ``toml.loads(s, _dict=dict)``
  171. Parse a TOML-formatted string to a dictionary.
  172. :Args:
  173. * ``s``: The TOML-formatted string to be parsed
  174. * ``_dict``: Specifies the class of the returned toml dictionary
  175. :Returns:
  176. A dictionary (or object ``_dict``) containing parsed TOML data
  177. :Raises:
  178. * ``TypeError``: When a non-string object is passed
  179. * ``TomlDecodeError``: When an error occurs while decoding the
  180. TOML-formatted string
  181. ``toml.dump(o, f, encoder=None)``
  182. Write a dictionary to a file containing TOML-formatted data
  183. :Args:
  184. * ``o``: An object to be converted into TOML
  185. * ``f``: A File descriptor where the TOML-formatted output should be stored
  186. * ``encoder``: An instance of ``TomlEncoder`` (or subclass) for encoding the object. If ``None``, will default to ``TomlEncoder``
  187. :Returns:
  188. A string containing the TOML-formatted data corresponding to object ``o``
  189. :Raises:
  190. * ``TypeError``: When anything other than file descriptor is passed
  191. ``toml.dumps(o, encoder=None)``
  192. Create a TOML-formatted string from an input object
  193. :Args:
  194. * ``o``: An object to be converted into TOML
  195. * ``encoder``: An instance of ``TomlEncoder`` (or subclass) for encoding the object. If ``None``, will default to ``TomlEncoder``
  196. :Returns:
  197. A string containing the TOML-formatted data corresponding to object ``o``
  198. Licensing
  199. =========
  200. This project is released under the terms of the MIT Open Source License. View
  201. *LICENSE.txt* for more information.