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