Yafra edited this page Jan 31, 2016 · 7 revisions

python

"Python is a programming language that lets you work quickly and integrate systems more effectively."

Python is a C like scripting language with many additional modules to handle all sorts of tasks. As editor you can either use Eclipse with PyDev (in our examples it is used with the Eclipse CPP edition) or PyCharm from JetBrains. PyCharm offers full integration with python including management of modules and environments, support for GAE, Flask, ...

Administration

Python dependencies are managed through a local requirements.txt file listing all dependencies. Usually a

pip install -r requirements.txt

is run to install dependencies.

You can create a dependency file by

pip freeze > requirements1.txt

Common modules used in yafra:

  • Pillow
  • PyMySQL and/or official Mysql Connector Python (install via tar file if you run Python27 and Pyhton3 on the same machine)
  • Flask
  • Jinja2
  • SQLAlchemy (and sqlacodegen to generate models out of legacy)
  • Werkzeug
  • MarkupSafe
  • numpy

Eclipse CPP edition with PyDev is used as IDE. ActivePython (32bit as those enables free access to required modules) 2.7 is used.

Tests

unittest

The standard python unittest is used. The default structure is a directory "test" and put your test python scripts into this folder. With python 3 you can execute python3 -m unittest test/TestApp.py and with python 2 you can execute python -m unittest test.TestApp.

Apps

Direct MySQL script

Simple query of database with direct DB API (mysql-connector in this example). https://github.com/yafraorg/yafra-tdb-python/tree/master/utils/mysql-connector

DB-API script

Simple query with MySqlDB driver - working on Python 2.7 and Python 3 https://github.com/yafraorg/yafra-tdb-python/tree/master/utils/db-api

SQL Alchemy

A python ORM which has a utility to reverse engineer existing databases and create python model files.

./sqlacodegen mysql+pymysql://yafraadmin:yafra@localhost/yafra > model.py

Afterwards SQL Alchemy can be used with this model. https://github.com/yafraorg/yafra-tdb-python/tree/master/utils/alchemy

Gtk client

A python example using Gtk/Glade as user interface framework and communicating with a daemon using a character based TCP socket communication. See the Python-GTK3 example and code: https://github.com/yafraorg/yafra-tdb-python/tree/master/admin-ui

Google App Engine

A web based example using GAE Big Table datastore.

  • a full example of an app engine using python (based on webapp2/jinja2)

https://github.com/yafraorg/yafra-toroam

Flask

A web based example using Flask/Eve. Similar to GAE but independent of GAE environment. Can be used on OpenShift.

  • Flask with SQL Alchemy
  • using OpenShift or own environment

https://github.com/yafraorg/yapki

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.