All Projects → uiri → Toml

uiri / Toml

Licence: mit
Python lib for TOML

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Toml

Hex
Package manager for the Erlang VM
Stars: ✭ 699 (-1.96%)
Mutual labels:  hacktoberfest
Awesome Startup
😎 All the required resources to build your own startup
Stars: ✭ 702 (-1.54%)
Mutual labels:  hacktoberfest
Artisan View
👀 Manage your views in Laravel projects through artisan
Stars: ✭ 708 (-0.7%)
Mutual labels:  hacktoberfest
Silverstripe Framework
SilverStripe Framework, the MVC framework that powers SilverStripe CMS
Stars: ✭ 700 (-1.82%)
Mutual labels:  hacktoberfest
Haproxy Ingress
HAProxy Ingress
Stars: ✭ 702 (-1.54%)
Mutual labels:  hacktoberfest
Laravel Boilerplate
Laravel Boilerplate / Starter Kit with Gentelella Admin Theme
Stars: ✭ 704 (-1.26%)
Mutual labels:  hacktoberfest
Rotki
A portfolio tracking, analytics, accounting and tax reporting application that protects your privacy
Stars: ✭ 689 (-3.37%)
Mutual labels:  hacktoberfest
Terjira
Terjira is a very interactive and easy to use CLI tool for Jira.
Stars: ✭ 713 (+0%)
Mutual labels:  hacktoberfest
Team Comtress 2
Team Fortress 2, but with a lot of fixes, QoL improvements and performance optimizations!
Stars: ✭ 701 (-1.68%)
Mutual labels:  hacktoberfest
Mercurius
Implement GraphQL servers and gateways with Fastify
Stars: ✭ 704 (-1.26%)
Mutual labels:  hacktoberfest
Tech Refrigerator
🍰 기술 냉장고입니다. 🛒 기술 면접 , 전공 시험 , 지식 함양 등 분명 도움될 거예요! 🤟
Stars: ✭ 699 (-1.96%)
Mutual labels:  hacktoberfest
Oak
Meaningful control of data in distributed systems.
Stars: ✭ 698 (-2.1%)
Mutual labels:  hacktoberfest
Natasha
基于 Roslyn 的 C# 动态程序集构建库,该库允许开发者在运行时使用 C# 代码构建域 / 程序集 / 类 / 结构体 / 枚举 / 接口 / 方法等,使得程序在运行的时候可以增加新的模块及功能。Natasha 集成了域管理/插件管理,可以实现域隔离,域卸载,热拔插等功能。 该库遵循完整的编译流程,提供完整的错误提示, 可自动添加引用,完善的数据结构构建模板让开发者只专注于程序集脚本的编写,兼容 stanadard2.0 / netcoreapp3.0+, 跨平台,统一、简便的链式 API。 且我们会尽快修复您的问题及回复您的 issue.
Stars: ✭ 705 (-1.12%)
Mutual labels:  hacktoberfest
Fae
CMS for Rails. For Reals.
Stars: ✭ 701 (-1.68%)
Mutual labels:  hacktoberfest
Adele
Adele - Design Systems Repository
Stars: ✭ 710 (-0.42%)
Mutual labels:  hacktoberfest
Filmy
🎥 Material designed awesome movie app which is powered by tmdb.
Stars: ✭ 697 (-2.24%)
Mutual labels:  hacktoberfest
Asimov
Automatically exclude development dependencies from Apple Time Machine backups
Stars: ✭ 705 (-1.12%)
Mutual labels:  hacktoberfest
Go Carbon
Golang implementation of Graphite/Carbon server with classic architecture: Agent -> Cache -> Persister
Stars: ✭ 713 (+0%)
Mutual labels:  hacktoberfest
Grunt Contrib Jshint
Validate files with JSHint.
Stars: ✭ 711 (-0.28%)
Mutual labels:  hacktoberfest
Grunt Cli
Grunt's command line interface.
Stars: ✭ 706 (-0.98%)
Mutual labels:  hacktoberfest

TOML


.. image:: https://img.shields.io/pypi/v/toml :target: https://pypi.org/project/toml/

.. image:: https://travis-ci.org/uiri/toml.svg?branch=master :target: https://travis-ci.org/uiri/toml

.. image:: https://img.shields.io/pypi/pyversions/toml.svg :target: https://pypi.org/project/toml/

A Python library for parsing and creating TOML <https://en.wikipedia.org/wiki/TOML>_.

The module passes the TOML test suite <https://github.com/BurntSushi/toml-test>_.

See also:

  • The TOML Standard <https://github.com/toml-lang/toml>_
  • The currently supported TOML specification <https://github.com/toml-lang/toml/blob/v0.5.0/README.md>_

Installation

To install the latest release on PyPI <https://pypi.org/project/toml/>_, simply run:

::

pip install toml

Or to install the latest development version, run:

::

git clone https://github.com/uiri/toml.git cd toml python setup.py install

Quick Tutorial

toml.loads takes in a string containing standard TOML-formatted data and returns a dictionary containing the parsed data.

.. code:: pycon

import toml toml_string = """ ... # This is a TOML document. ... ... title = "TOML Example" ... ... [owner] ... name = "Tom Preston-Werner" ... dob = 1979-05-27T07:32:00-08:00 # First class dates ... ... [database] ... server = "192.168.1.1" ... ports = [ 8001, 8001, 8002 ] ... connection_max = 5000 ... enabled = true ... ... [servers] ... ... # Indentation (tabs and/or spaces) is allowed but not required ... [servers.alpha] ... ip = "10.0.0.1" ... dc = "eqdc10" ... ... [servers.beta] ... ip = "10.0.0.2" ... dc = "eqdc10" ... ... [clients] ... data = [ ["gamma", "delta"], [1, 2] ] ... ... # Line breaks are OK when inside arrays ... hosts = [ ... "alpha", ... "omega" ... ] ... """ parsed_toml = toml.loads(toml_string)

toml.dumps takes a dictionary and returns a string containing the corresponding TOML-formatted data.

.. code:: pycon

new_toml_string = toml.dumps(parsed_toml) print(new_toml_string) title = "TOML Example" [owner] name = "Tom Preston-Werner" dob = 1979-05-27T07:32:00Z [database] server = "192.168.1.1" ports = [ 8001, 8001, 8002,] connection_max = 5000 enabled = true [clients] data = [ [ "gamma", "delta",], [ 1, 2,],] hosts = [ "alpha", "omega",] [servers.alpha] ip = "10.0.0.1" dc = "eqdc10" [servers.beta] ip = "10.0.0.2" dc = "eqdc10"

toml.dump takes a dictionary and a file descriptor and returns a string containing the corresponding TOML-formatted data.

.. code:: pycon

with open('new_toml_file.toml', 'w') as f: ... new_toml_string = toml.dump(parsed_toml, f) print(new_toml_string) title = "TOML Example" [owner] name = "Tom Preston-Werner" dob = 1979-05-27T07:32:00Z [database] server = "192.168.1.1" ports = [ 8001, 8001, 8002,] connection_max = 5000 enabled = true [clients] data = [ [ "gamma", "delta",], [ 1, 2,],] hosts = [ "alpha", "omega",] [servers.alpha] ip = "10.0.0.1" dc = "eqdc10" [servers.beta] ip = "10.0.0.2" dc = "eqdc10"

For more functions, view the API Reference below.

Note

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.

.. code:: pycon

import toml import numpy as np a = np.arange(0, 10, dtype=np.double) output = {'a': a} toml.dumps(output) 'a = [ "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "9.0",]\n' toml.dumps(output, encoder=toml.TomlNumpyEncoder()) 'a = [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0,]\n'

API Reference

toml.load(f, _dict=dict) Parse a file or a list of files as TOML and return a dictionary.

:Args: * f: A path to a file, list of filepaths (to be read into single object) or a file descriptor * _dict: The class of the dictionary object to be returned

:Returns: A dictionary (or object _dict) containing parsed TOML data

:Raises: * TypeError: When f is an invalid type or is a list containing invalid types * TomlDecodeError: When an error occurs while decoding the file(s)

toml.loads(s, _dict=dict) Parse a TOML-formatted string to a dictionary.

:Args: * s: The TOML-formatted string to be parsed * _dict: Specifies the class of the returned toml dictionary

:Returns: A dictionary (or object _dict) containing parsed TOML data

:Raises: * TypeError: When a non-string object is passed * TomlDecodeError: When an error occurs while decoding the TOML-formatted string

toml.dump(o, f, encoder=None) Write a dictionary to a file containing TOML-formatted data

:Args: * o: An object to be converted into TOML * f: A File descriptor where the TOML-formatted output should be stored * encoder: An instance of TomlEncoder (or subclass) for encoding the object. If None, will default to TomlEncoder

:Returns: A string containing the TOML-formatted data corresponding to object o

:Raises: * TypeError: When anything other than file descriptor is passed

toml.dumps(o, encoder=None) Create a TOML-formatted string from an input object

:Args: * o: An object to be converted into TOML * encoder: An instance of TomlEncoder (or subclass) for encoding the object. If None, will default to TomlEncoder

:Returns: A string containing the TOML-formatted data corresponding to object o

Licensing

This project is released under the terms of the MIT Open Source License. View LICENSE.txt for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].