Interacting with the Acquia Cloud API using Python

The Acquia Cloud API makes it easy to manage sites on the platform. The API allows you to perform many administrative tasks including creating, destroying and copying databases, deploying code, managing domains and copying files.

Acquia offers 2 official clients. The primary client is a drush plugin which can only be downloaded from Acquia Insight. The other is a PHP library which states in the README that it is "[n]ot ready for production usage".

On a recent project using WF Tools we needed some pretty advanced deployment scripts for sites hosted on Acquia Cloud. We had tried using a mix of bash and PHP, but that created a maintenance nightmare, so we switched to Python.

I was unable to find a high quality Python library, so I wrote a python client for the Acquia Cloud API. The library implements all of the features that we needed, so there are a few things missing.

Chaining complex commands together is easy because the library implements a fluent interface. An extreme example of what is possible is below:

import acapi

# Instantiate the client
c = acapi.Client([email protected]', 'acquia-token')

# Copy the prod db to dev, make a backup of the dev db and download it to /tmp'mysite').environment('prod').db('mysite').copy('dev').backups().create().download('/tmp/backup.sql.gz')

Some of the code is "borrowed" from the Python client for Twilio. The library is licensed under the terms of the MIT license.

I am continuing to develop the library. Consider this a working alpha. Improving error handling, creating a comprehensive test suite and implementing the missing API calls are all on the roadmap. Pull requests are welcome.

The code is PEP 8 (coding standards and PEP 257 (documentation standards) compliant and uses the numpydoc for code documentation.

Check out the Python client for Acquia's Cloud API on github.

Did you look at the Acquia SDK for PHP?

Chris Pliakas wrote:

Hi Dave.

I wanted to raise your attention to the Acquia SDK for PHP which has a client library for Cloud API and other Acquia services as well.

Thanks, Chris

Added Tue, 2014-07-22 00:29

RE: Did you look at the Acquia SDK for PHP?

Dave wrote:

@Chris I looked at Acquia's SDK, but not until significant effort had been spent on the Python library. On thing that counted against it was that's written in PHP. We were using a mix of bash and php, often for completing the one task. This was unmaintainable mess.

We wanted a single language that was designed to be used for scripting. The choices were:

  • PHP
    The team has a lot of PHP experience, but PHP isn't the best language for devops tasks.
  • Python
    There is a lot of Python libraries for devops tasks and most of the team had done some Python in the past.
  • Ruby
    Like Python, Ruby is well suited to devops scripts, but we lacked anyone of the team with strong Ruby skills.
  • Go
    I would have loved to have tried go for this project, but the timelines didn't allow for the whole team learning a new language.

Python was the best option available to us.

Added Tue, 2014-07-22 12:27

Thanks for the rationale,

Chris Pliakas wrote:

Thanks for the rationale, makes sense to me. I totally understand why Python is a great choice for devops tasks, and thanks for detailing your thoughts on using the other languages for your purposes.

Best of luck! Chris

Added Wed, 2014-07-23 04:47

The information about the

Anonymous wrote:

The information about the acquia cloud api python is really very informative..Thanks for sharing these types of informative...

Added Tue, 2017-01-24 22:55

useful post

Python Training in Hyderabad wrote:

python scripting is being used in many coding areas.

Python Training in Hyderabad

Added Mon, 2017-03-13 22:34

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <div> <blockquote> <pre>

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.