Git Product home page Git Product logo

python-dict2xml's Introduction

dict2xml

Super Simple utility to convert a python dictionary into an xml string

Installation

Make youself a virtualenv and do the following:

$ pip install .

Or if you want to develop on dict2xml, recommended commands are:

$ pip install -e .
$ pip install -e ".[tests]"

Or if you don't want to install from source:

$ pip install dict2xml

example

from dict2xml import dict2xml as xmlify
data = {
    'a' : 1
  , 'b' : [2, 3]
  , 'c' : {
      'd' : [
          {'p' : 9}
        , {'o' : 10}
        ]
      , 'e': 7
      }
  }

print xmlify(data, wrap="all", indent="  ")

Output

<all>
  <a>1</a>
  <b>2</b>
  <b>3</b>
  <c>
    <d>
      <p>9</p>
    </d>
    <d>
      <o>10</o>
    </d>
    <e>7</e>
  </c>
</all>

methods

dict2xml.dict2xml(data, *args, **kwargs)

Equivalent to:

dict2xml.Converter(*args, **kwargs).build(data)
dict2xml.Converter(wrap="", indent=" ", newlines=True)

Knows how to convert a dictionary into an xml string

  • wrap: Wraps the entire tree in this tag
  • indent: Amount to prefix each line for each level of nesting
  • newlines: Whether or not to use newlines
dict2xml.Converter.build(data)
Instance method on Converter that takes in the data and creates the xml string

Limitations

  • No attributes on elements
  • Currently no explicit way to hook into how to cope with your custom data
  • Currently no way to insert an xml declaration line

Changelog

1.6.1
  • Include readme and LICENSE in the package
1.6
  • No code changes
  • changed the licence to MIT
  • Added more metadata to pypi
  • Enabled travis ci
  • Updated the tests slightly
1.5
  • No changelog was kept before this point.

python-dict2xml's People

Contributors

delfick avatar shalakhin avatar nilp0inter avatar lmartinking avatar kitterma avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.