0

I am loading a big yaml file and it is taking forever. I am wondering if there is a faster method than the yaml.load() method.

I have read that there is a CLoader method but havent been able to run it.

The website that suggested this CLoader method asks me to do this:

Download the source package PyYAML-3.08.tar.gz and unpack it. 
Go to the directory PyYAML-3.08 and run:
    $ python setup.py install


If you want to use LibYAML bindings, which are much faster than the pure Python version, you need to download and install LibYAML. 
Then you may build and install the bindings by executing
    $ python setup.py --with-libyaml install

In order to use LibYAML based parser and emitter, use the classes CParser and CEmitter:

    from yaml import load, dump
    try:
       from yaml import CLoader as Loader, CDumper as Dumper
    except ImportError:
       from yaml import Loader, Dumper

This looks like this will work but I dont have a setup.py directory anywhere in my Django project and therefore can't install/import any of these things

Can anyone help me figure out how to do this or let me know about another faster loading method??

Thanks for the help!!

Santiago
  • 1,984
  • 4
  • 19
  • 24
  • 1
    I've done a bit of research around the web looking for a fast way to load YAML, and the fastest way is... well, `yaml.load()`. You may want to check out the [pyyaml documentation](http://pyyaml.org/wiki/PyYAMLDocumentation) to see of there is a more efficient way of loading it, otherwise check out [this article](http://stackoverflow.com/questions/1773805/best-way-to-parse-a-yaml-file). I've not done a whole lot like this, but [pysyck](http://pyyaml.org/wiki/PySyck) may work as well. Hope that helps a bit. – Ben Schwabe Sep 07 '12 at 02:13
  • In my case I had PyYAML already installed without libyaml, so I installed libyaml and did a `pip install --no-deps --ignore-installed PyYAML` to reinstall pyyaml. I didn't need to do the `setup.py` step. – dusan Sep 06 '13 at 22:24

1 Answers1

-1

I have no idea what's faster - bspymaster's ideas might be the most useful.

When you download PyYAML-3.08.tar.gz, inside the archive there will be a setup.py what you can run.

Note to use LibYAML, download this: http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz

And run using the instructions from http://pyyaml.org/wiki/LibYAML

You will need a set a build tools, which should be installed on linux/unix, for osx make sure xcode is installed, and I'm not sure about windows.

Adam Morris
  • 8,265
  • 12
  • 45
  • 68