Categories: Custom Transformer Examples | Web Services Custom Transformers | Web Services | Python Sample | FME Objects Sample
Google Spreadsheets Python Read-Writelet
From fmepedia
The Google Spreadsheets Python Read/Writelet is a FME solution for reading and writing Google Spreadsheet data. It is made up of three Custom Transformers containing PythonCaller transformers. The underlying Python scripts utilize the FME Objects Python API (PyFME) (http://www.fmepedia.com/index.php/Python_and_FME) and the Google Data (gData) Python API (http://code.google.com/p/gdata-python-client/) to read and write data.
Requirements
- FME 2008
- PyFME
- Python 2.4
- Python cElementTree (tested with 1.2.6)
- gdata-python-client (tested with 1.0.10)
- Install the four Python modules in a directory where Python can access them.
- Install the three custom transformers.
- If you have more than one version of Python installed, you may need to set the FME_PYTHON_VERSION directive in the workspace header.
Contents of the Read/Writelet package (gDataWiseReadWritelet.zip (http://fmepedia.com/attachments//Google_Spreadsheets_Python_Read-Writelet/gDataWiseReadWritelet.zip))
Python Modules/Classes:
- gDataWiseBase.py: a Python module and a single class providing common functions for the readlet/writelet (e.g. authentication), which are extended/inherited by the other classes.
- gDataWiseReader.py: a Python module and a single class that reads row data from a Google spreadsheet. The class implements the PythonCaller transformer's interface requirements.
- gDataWiseFastWriter.py: a Python module and a single class that writes non-geometry features to rows in a Google spreadsheet. The class implements the PythonCaller transformer's interface requirements. This implementation is faster than gdataWiseWriterFull.py, but lacks some of its functionality (full document output, single worksheet per spreadsheet).
- gDataWiseFullWriter.py: a Python module and a single class that writes non-geometry features to rows in a Google spreadsheet. The class implements the PythonCaller transformer's interface requirements. This implementation is slower than gdataWiseWriterFast.py, but has more functionality (individual row output, multiple worksheets in a spreadsheet).
Custom Transformers:
- gDataWiseReader.fmx: a custom transformer containing a PythonCaller transformer that outputs Google spreadsheet/worksheet rows as features. You will need to expose any attributes that you wish to manipulate within a workspace.
- gDataWiseFastWriter.fmx: a custom transformer containing an Aggregator transformer and a PythonCaller transformer that takes input features and writes them as rows in a Google spreadsheet/worksheet. This writelet is faster, but has less functionality than the Full writelet.
- gDataWiseFullWriter.fmx: a custom transformer containing an Aggregator transformer and a PythonCaller transformer that takes input features and writes them as rows in a Google spreadsheet/worksheet. This writelet is slower, but has more functionality than the Fast writelet.
Example Workspaces:
- gDataWiseReader_example.fmw: sample workspace showing use of gDataWiseReader custom transformer (below).
- gDataWiseFullWriter_example.fmw: sample workspace showing use of gDataWiseFullWriter custom transformer (below).
- gDataWiseFastWriter_example.fmw: sample workspace showing use of gDataWiseFastWriter custom transformer (below).
Notes
- Google Data (gData) Python API (http://gdata-python-client.googlecode.com/svn/trunk/pydocs/gdata.html) is used to interact with Google Spreadsheets.
- The Google Spreadsheet's service name is 'wise'.
- Overall the gData API is incomplete; missing functionality such as rename spreadsheet, download spreadsheet, create blank spreadsheet, etc. A lot of functionality is implemented in a round about way, such as creating and uploading an empty CSV file in order to create a blank spreadsheet.
- In general, reading and writing rows/features is slow.
- The Full version of the writelet inserts one feature at a time.
- This is really slow, but enables the use of multiple worksheets in a spreadsheet.
- The Fast version of the writelet creates a full CSV file first and then uploads it as a new spreadsheet.
- This is fast, but there is no way to upload a CSV file into an existing spreadsheet (i.e. as a new worksheet in an existing spreadsheet) or even copy a worksheet from one spreadsheet to another (as a workaround).
- The Full version of the writelet inserts one feature at a time.
