Is there a non-blender API for producing blend files? I have a python application which creates 3d models. It is already able to export these models as FBX, DAE, OBJ etc. In the vast majority of cases, the next step in the pipeline is touching up the model inside blender, which means I then have to import the models in blender from the said export formats. 

However, some blender-specific features aren't possible to express in these file formats. The obvious idea to solve this would be exporting directly to a blend file instead of to a third-part unrelated file format. 

Researching ways to do this, I've found http://wiki.blender.org/index.php/User%3aIdeasman42/BlenderAsPyModule which seems like one approach. However, this seems to require a custom-built blender.

I have also found the binary specifications for the file format, notably http://wiki.blender.org/index.php/Dev:Source/Data_Structures/DNAStructs and (some other links which I'm not allowed to include in the post atm).

... so obviously it'd be possible (albeit cumbersome) to write an export function with a bit of trial an error. 

However, before I do this: Has this already been done? Is there an existing library/API out there for producing blend files outside blender?
I don't know of how to export directly to Blender (seems overly complicated), but you could import PLY/STL/etc files, and then script all the additional features you want.

In my case, I was free to choose the original CAD program, so I chose to build directly in Blender via the PyModule. I work with Blender completely separate from the GUI, and rely only on an external python3 and the bpy module. The bpy module is easy to make.. and you can keep it largely separate from your existing blender install (I run from source folder).

Just run this command (make sure you don't have a $HOME/src):

git clone http://git.blender.org/blender.git &amp;&amp; cd blender &amp;&amp; git submodule update --init --recursive &amp;&amp; git submodule foreach git checkout master &amp;&amp; git submodule foreach git pull --rebase origin master &amp;&amp; build_files/build_environment/install_deps.sh --with-all --skip-osl &amp;&amp; sudo make bpy &amp;&amp; cd .. &amp;&amp; rm -rf blender &amp;&amp; sudo rm -rf build_linux_bpy &amp;&amp; rm -rf $HOME/src # this gets bpy python module


I also found this: https://code.google.com/p/pyblenderfile/
but, honestly, I don't see much benefit. Its not developed enough to allow importing everything, so I found a better way of doing the same thing using the bpy module.

What I do is this:

-- build stuff in blender (I do it via python, without ever starting the official application)

import bpy
#build stuff
bpy.ops.wm.save_as_mainfile(filepath="./objects8.blend")


-- import the model

import bpy
bpy.ops.wm.open_mainfile(filepath="./objects8.blend")


Works great for me. I have some issues recreating stuff you can do in the GUI, but its mostly because Blender has terrible documentation for code (imo). Still, you can do sweet stuff since you call all the equivalent commands directly in python and it executes using the bpy module.