Product Documentation

FairCom SQLAlchemy for Python

Previous Topic

Next Topic

SQLAlchemy Support

SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL. The FairCom DB SQL Python interface provides support for this technology.

More details about SQLAlchemy are available at SQLAlchemy.org.

To get started with SQLAlchemy, see the following folder:

\drivers\python.sql.sqlalchemy

In This Section

Preferred Configuration

Installing the FairCom DB SQLAlchemy Dialect

Running the Tutorial

Troubleshooting on Linux

A Note About IP Addresses and Localhost

Previous Topic

Next Topic

Preferred Configuration

FairCom recommends that the tutorials for the Python APIs be run using Python version 3 - preferably version 3.4+. Accordingly, in the instructions below, we have made the following assumptions about how the user's machine is configured:

Windows: The PATH, etc. should be configured in such a way that invoking python at the command-line will run version 3 of Python and invoking pip at the command-line will run the instance of pip that is associated with that version of Python.

Linux: The system should be configured in such a way that invoking python3 at the command-line will run version 3 of Python and invoking pip3 at the command-line will run the instance of pip that is associated with that version of Python.

These assumptions are also made by the batch files (Windows) and make files (Linux) FairCom provides to run the tutorials and by the instructions bellow. If these assumptions are not correct, users are encouraged to reconfigure their machines to match the assumptions. Alternatively, you can modify the instructions that follow and the batch file and/or make file to match the machine's configuration.

Bit Depth: It is important that the bit depth of the Python version 3 you are using matches the bit depth of the FairCom product you are using.

Previous Topic

Next Topic

Installing the FairCom DB SQLAlchemy Dialect

This package contains the FairCom DB SQL dialect for SQLAlchemy. The dialect enables using FairCom DB SQL with SQLAlchemy, the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL. More details are available at SQLAlchemy.org.

Note: This driver was specifically developed and tested on SQLAlchemy 1.0.19 with both Python 2.7 and Python 3.5-3.9. It supports SQLAlchemy 1.0 and higher and Python 2.7 and Python 3.0 forward.

Installation

  1. Make sure you have Python 2.7 or 3.0 and higher installed and in your path.
  2. Make sure you have SQLAlchemy 1.0 or higher installed.

    Reminder: setuptools and wheel are prerequisites before SQLAlchemy can be installed on Linux. If you do not have them installed, execute the following before installing SQLAlchemy:
    pip install setuptools
    pip install wheel

  3. Make sure you have the FairCom DB SQL Python driver installed. In a command window, change into the FairCom DB SQL SQLAlchemy dialect folder:

    <faircom>\drivers\python.sql.sqlalchemy

  4. Execute the following command found in the above folder:
    python setup.py install

Windows:

  1. Launch a command prompt as administrator.
  2. Run the following command:

    pip install sqlalchemy

  3. Change to the <faircom>\drivers\python.sql.sqlalchemy directory
  4. Run the following command:

    python setup.py install

Linux:

  1. Bring up a shell.
  2. Run the following command:

    pip3 install sqlalchemy

  3. Change to the <faircom>/drivers/python.sql.sqlalchemy directory
  4. Run the following command:

    python3 setup.py install

If any steps have permission problems, use sudo to run that command.

If step 4 produces the following error, you will need to update your setuptools package:

setuptools_scm.version.SetuptoolsOutdatedWarning: your setuptools is too old (<12)

Un-install the old version of the Python setuptools package and install a later version, as follows:

  • Python 3.x - Install the latest version of setuptools: pip/pip3 install setuptools
  • Python 2.x - Install the last version of setuptools that still supports Python 2.x: pip/pip3 install setuptools==44

After updating setuptools, try step 4 again.

Previous Topic

Next Topic

Running the Tutorial

To run the tutorial (after doing the installations mentioned above), use the batch file (Windows) or make file (Linux) in the <faircom>\drivers\python.sql.sqlalchemy\tutorials\cmdline folder, as follows:

  1. Change to the directory:

    cd tutorials\cmdline

  2. Run the appropriate command:

    Windows: BuildTutorials.bat

    Linux: make build; make run

    On Linux, the build command copies a library to the correct location and the run command runs the tutorial.

The tutorial should print the following:

<User(id='1', name='u1')>

[<Address(email='one')>, <Address(email='two')>]

Previous Topic

Next Topic

Troubleshooting on Linux

Problem: "ImportError: No module named setuptools"

Solution: Install setuptools as described above.


Problem: "pyctree missing"

Solution: Be sure you have installed pyctree as described above.


Problem: sql.sqlalchemy can fail with "shared library not found."

Solution: Run one of the following:

  • For CSH (c shell):

setenv LD_LIBRARY_PATH /<PATH_TO_YOUR_CTREE_SERVER>/drivers/sql.python/

  • For BASH (Bourne-Again SHell):

export LD_LIBRARY_PATH=<PATH_TO_YOUR_CTREE_SERVER>/drivers/sql.python/

Previous Topic

Next Topic

A Note About IP Addresses and Localhost

The python tutorials currently use “127.0.0.1” to connect to the c-tree server on the local machine instead of using “localhost”. This is because Windows 10 often has “localhost” commented out of its “hosts” file (%systemroot%\System32\drivers\etc\hosts), as follows:

# localhost name resolution is handled within DNS itself.

#127.0.0.1 localhost

#::1 localhost

Unfortunately, Python does not seem to use DNS to resolve "localhost", which means that these tutorials are unable to connect to the c-tree server on some versions of Windows if they use “localhost” instead of “127.0.0.1”. By using “127.0.0.1” in our Python tutorials, we work around this problem.

If you are using IPv6, or have some other situation where “127.0.0.1” is not appropriate, feel free to update the call to create_engine() in the demonstration file, <faircom>\drivers\python.sql.sqlalchemy\tutorials\usage.py

TOCIndex