Python binding to ImageMagick - python

I am looking for a good Python binding to ImageMagick, but there seem a lot of bindings already. I am not sure that which of these is the right tool for my job. Can you guys recommend me one?
Here is the list of my requirements and preferences (in order of importance):
Must be available on PyPI (to simplify our deployment)
Prefer ctypes over C API extension — we will go PyPy soon
Pythonic API design and naming conventions
Good documentation (especially API references)

I found the package myself: magickwand is a ctypes-based ImageMagick binding for Python. Yet it has no documentation at all, it still satisfies most of my requirements.
Plus: I finally started my own project: Wand.

Related

How to use shared dynamic libraries with python-cffi (in linux)?

OS: CentOS 6 (64bit)
I have a dynamic library (.so) in C. And I want to create an abstraction layer of Python over it and then use it to implement my logic. I have decided to use CFFI for this since it doesn't deal with any kind of dsl (domain specific language).
Couple of things I wanted to know:
Is there some good starting point which I can refer for doing this (loading and using dynamic libraries using cffi)? The docs on the official site talk about this, but I was looking if there was some concrete reference somewhere with some examples. Or someone who might have tried it.
Can there a possible drawback to this approach?
Thanks
Two good starting points:
The CFFI documentation, and specifically the ABI out of line example: https://cffi.readthedocs.org/en/latest/overview.html#out-of-line-example-abi-level-out-of-line
My CFFI example repository: https://github.com/wolever/python-cffi-example
Between the two you shouldn't have too much trouble putting together your wrapper.
And to your second question: if the shared library you're wrapping is very simple (ex, a few function calls, simle data structures) you might find ctypes simpler (as it's part of the standard library).

Does a Python implementation of, or interface to, UCL exist?

UCL can be found here:
http://www.oberhumer.com/opensource/ucl/
I am wondering if there is a Python implementation of this library or, at minimum, a simple interface (via SWIG, or even ctypes) exists?
The only evidence I could find of such an implementation led me here:
https://build.opensuse.org/package/show?package=python-ucl-common&project=home%3Asjcundy%3AAccessGrid
Which when you try to download the package, you receive an error page.
Maybe this answer is a little late, but I've just done a simple implementation using cffi (https://bitbucket.org/cffi/cffi).
You can find it at https://github.com/jap/pyucl (only tested on Linux)
Many compression algorithms are available for Python, in zlib, bz2, zipfile, and externally, for example lzo (on the same web site as UCL).
If you really need UCL, try cTypesGen, which should automatically be able to provide you a Python interface to it.

Should I bundle C libraries with my Python application?

If I have a Python package that depends on some C libraries (like say the Gnu Scientific Library (GSL) for numerical computations), is it a good idea to bundle the library with my code?
I'd like to make my package as easy to install as possible for users and I don't want them to have to download C libraries by hand and supply include-paths. Also I could always ensure that the version of the library that I ship is compatible with my code.
However, is it possible that there are clashes if the user has the library installed already, or ar there any other reasons why I shouldn't do this?
I know that I can make it easier for users by just providing a binary distribution, but I'd like to avoid having to maintain binary distributions for all possible OSs. So, I'd like to stick to a source distribution, but for the user (who proudly owns a C compiler) installation should be as easy as python setup.py install.
Distribution is one of the hard parts for any software project. Java and .NET lift part of this burden by defining a standard runtime and then just saying "just distribute everything else." Of course there's a drawback: everything must be rewritten in a language supported by the runtime - as soon as you want to use native code, you lose all the advantages.
That's harder in Python, as it is in Ruby, C, C++ and other languages, as they usually leverage existing native libraries.
Generally speaking:
Make it possible to get a source sdist, via pypi.python.org as an example. Correctly set your install_requires (probably you'll require python bindings for GSL, not GSL itself). Use standard setuptools/distribute layout. This will let anyone - let's say a package maintainer for any distro - to pick up your software and package it.
Additionally, consider providing a full-blown installable package for your audience. You don't have to support all the distros and operating system; pick one or two that you consider will be used most. Tools like PyInstaller will let you create an installable, runnable package for many operating systems, but especially for linux you might want the user to install the distribution's own version of transitive deps (libgsl?) - you'll need a full-blown deb or rpm package to satisfy that - again, don't try supporting any and all the distro, you'll turn out mad. Support something you most use, and let other users to help you with other packaging needs.
Also take a look at Python Packaging Guide
You could have two separate branches of the src, one containing the libraries and another that doesn't. That way you can explicitly warn your users in case they have installed the libraries. Another solution could be (if the licences of the libraries allow you) is to wrap 'em up in a single file.
I think there's no unique solution, but this are the ideas I could think so far.
Good luck
You can use virtualenv to create a private Python environment for your application. This avoids conflicts with other libraries. It is best if you package modules and dependencies such as your libraries using Distribute. Distutils is something else that is worth researching.

writing an api for python that can be installed using setup.py method

I am new at writing APIs in python, in any language for that matter. I was hoping to get pointers on how i can create an API that can be installed using setup.py method and used in other python projects. Something similar to the twitterapi.
I have already created and coded all the methods i want to include in the API. I just need to know how to implement the installation so other can use my code to leverage ideas they may have. Or if i need to format the code a certain way to facilitate installation.
I learn best with examples or tutorials.
Thanks so much.
It's worth noting that this part of python is undergoing some changes right now. It's all a bit messy. The most current overview I know of is the Hitchhiker's Guide to Packaging: http://guide.python-distribute.org/
The current state of packaging section is important: http://guide.python-distribute.org/introduction.html#current-state-of-packaging
The python packaging world is a mess (like poswald said). Here's a brief overview along with a bunch of pointers. Your basic problem (using setup.py etc.) is solved by reading the distutils guide which msw has mentioned in his comment.
Now for the dirt. The basic infrastructure of the distribution modules which is in the Python standard library is distutils referred to above. It's limited in some ways and so a series of extensions was written on top of it called setuptools. Setuptools along with actually increasing the functionality provided a command line "installer" called "easy_install".
Setuptools maintenance was not too great and so it was forked and a more active branch called "distribute" was setup and it is the preferred alternative right now. In addition to this, a replacement for easy_install named pip was created which was more modular and useful.
Now there's a huge project going which attempts to fold in all changes from distribute and stuff into a unified library that will go into the stdlib. It's tentatively called "distutils2".

What's a good library to do computational geometry (like CGAL) in a garbage-collected language?

I need a library to handle computational geometry in a project, especially boolean operations, but just about every feature is useful. The best library I can find for this is CGAL, but this is the sort of project I would hesitate to make without garbage collection.
What language/library pairs can you recommend? So far my best bet is importing CGAL into D. There is also a project for making Python bindings for CGAL, but it's very incomplete.
I would still recommend to proceed with Python and the existing Python binding. When you find it's incomplete, you'll also find that it is fairly easy to extend - Python's C API is designed so that integrating with external libraries is fairly easy (for experienced C programmers).
Perhaps you can look at Shapely for python
http://pypi.python.org/pypi/Shapely/
For Java I would use JTS
For .NET I would use SharpMap or .NETTopologySuite
The CGAL-bindings project provides bindings for CGAL using SWIG. The targeted languages, so far, are Java and Python. The CGAL-bindings project is open source, and supported/founded by two french companies.
JTS is also available in .NET via IKVM.
I've just found this and it seems very promising even if it seems a young project: https://pyrr.readthedocs.org/en/latest/index.html#
Pyrr is a Python mathematical library.
and it is based on numpy!

Categories

Resources