From BlenderWiki
This is an experimental option to be able to import blender into python and access its modules, importers, exporters rendering, video editing... etc.
This is mainly limited to features which can be usable in background mode, so you cant for instance do OpenGL preview renders.
Building
assuming you have a CMake out-of-source build setup, see: http://wiki.blender.org/index.php/Dev:2.5/Doc/Building_Blender/Linux/Ubuntu/CMake
OSX prerequisites: get Python3.2-Framework from Python.org and install it.
Change these CMake options from the defaults:
WITH_PYTHON_INSTALL=OFF WITH_PLAYER=OFF WITH_PYTHON_MODULE=ON
Now build blender normally with 'make install'
Everything should build as normal except in the cmake directory you will have ./bin/bpy.so rather then ./bin/blender
Installation
Linux
To make this available for python copy these files to your site-packages by running
make install
Or if you like to do it manually
cp ./bin/bpy.so /usr/lib/python3.2/site-packages/ cp --recursive ./bin/2.61 /usr/lib/python3.2/site-packages/
Windows
copy bin\bpy.pyd C:\Python32\Lib\site-packages\ copy bin\*.dll C:\Python32\Lib\site-packages\ del C:\Python32\Lib\site-packages\python32.dll xcopy /E bin\2.61 C:\Python32\
OSX
After compiling and "make install", copy needed files to your python framework
cp ./bin/bpy.so /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/ cp -R ./bin/2.61 /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/
Note. Unlike on *nix C:\Python32\2.57 is not in the site packages, this is because of a difference in how Windows finds the scripts path and should eventually be fixed.
Testing
This allows 'bpy' to be imported from python or other applications/IDE's which embed python, eg:
python -c "import bpy ; bpy.ops.render.render(write_still=True)"
This runs in background mode and has similar restrictions to running a script:
blender --background --python test.py