|
| 1 | +Get Started |
| 2 | +============ |
| 3 | + |
| 4 | + |
| 5 | +Install the latest release with conda |
| 6 | +------------------------------------- |
| 7 | + |
| 8 | +conda |
| 9 | +^^^^^ |
| 10 | + |
| 11 | +The easiest and most reliable way to install the ODM2 Python API |
| 12 | +(``odm2api``) is using the `Conda package management |
| 13 | +system <https://conda.io/docs/>`__ via either |
| 14 | +`Anaconda <https://www.anaconda.com/download/>`__ or |
| 15 | +`Miniconda <https://conda.io/miniconda.html>`__. To start using |
| 16 | +conda (if it's not your system default), add conda to the PATH; on |
| 17 | +OS X and Linux, it's something like |
| 18 | +``export PATH=$HOME/miniconda3/bin:$PATH``, but the exact path may vary. |
| 19 | + |
| 20 | +To activate a conda environment, say, "myenv": |
| 21 | + |
| 22 | +.. code-block:: bash |
| 23 | +
|
| 24 | + activate myenv # On Windows |
| 25 | + source activate myenv # On MacOSX or Linux |
| 26 | +
|
| 27 | +**Note:** ``odm2api`` currently is only tested on Python 2.7. Some |
| 28 | +changes have been made to support Python 3.x, but they haven't been |
| 29 | +tested thoroughly. |
| 30 | + |
| 31 | +Install the conda package |
| 32 | +^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 33 | + |
| 34 | +The `latest release <https://github.com/ODM2/ODM2PythonAPI/releases>`_ is available |
| 35 | +as a package on the `conda-forge anaconda.org channel <https://anaconda.org/conda-forge/odm2api>`_ |
| 36 | +for all major OS platforms (linux, OS X, win32/win64). To install it on |
| 37 | +an existing conda environment: |
| 38 | + |
| 39 | +:: |
| 40 | + |
| 41 | + conda install -c conda-forge odm2api |
| 42 | + |
| 43 | +All dependencies are installed, including Pandas and its dependencies |
| 44 | +(numpy, etc). |
| 45 | + |
| 46 | +To create a new environment "myenv" with the ``odm2api`` package: |
| 47 | + |
| 48 | +:: |
| 49 | + |
| 50 | + conda create -n myenv -c conda-forge python=2.7 odm2api |
| 51 | + |
| 52 | + |
| 53 | +Code examples |
| 54 | +------------- |
| 55 | + |
| 56 | +Connecting to an ODM2 database |
| 57 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 58 | + |
| 59 | +Connect to an ODM2 database and open the connection for reading. |
| 60 | + |
| 61 | +.. code-block:: python |
| 62 | +
|
| 63 | + from odm2api.ODMconnection import dbconnection |
| 64 | + import odm2api.services.readService as odm2rs |
| 65 | +
|
| 66 | + # A SQLite file-based connection |
| 67 | + session_factory = dbconnection.createConnection('sqlite', |
| 68 | + '/myfilepath/odm2db.sqlite') |
| 69 | + read = odm2rs.ReadODM2(session_factory) |
| 70 | +
|
| 71 | + # A connection to a server-based database system |
| 72 | + db_credentials = { |
| 73 | + 'address': 'ip-or-domainname', |
| 74 | + 'db': 'dbname', |
| 75 | + 'user': 'dbuser', |
| 76 | + 'password': 'password' |
| 77 | + } |
| 78 | + session_factory = dbconnection.createConnection('postgresql', |
| 79 | + **db_credentials) |
| 80 | + read = odm2rs.ReadODM2(session_factory) |
| 81 | +
|
| 82 | +
|
| 83 | +Updating an entity (table) |
| 84 | +^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 85 | + |
| 86 | +The `update services <https://github.com/ODM2/ODM2PythonAPI/blob/master/odm2api/services/updateService.py>`_ |
| 87 | +have not been fleshed out at this time, for the most part. However, updates can be easily |
| 88 | +accomplished by reusing the connection setup at the start of an odm2api session, |
| 89 | +then constructing and issuing a direct ``SQL UPDATE`` statement, like this: |
| 90 | + |
| 91 | +.. code-block:: python |
| 92 | +
|
| 93 | + from odm2api.ODMconnection import dbconnection |
| 94 | +
|
| 95 | + session_factory = dbconnection.createConnection('postgresql', |
| 96 | + **db_cred) |
| 97 | + DBSession = session_factory.getSession() |
| 98 | +
|
| 99 | + sq_str = " UPDATE mytable SET variablecode = 'xyz' WHERE variablecode = 'abc' " |
| 100 | + DBSession.execute(sql_str) |
| 101 | + DBSession.commit() |
| 102 | +
|
| 103 | +
|
| 104 | +Sample Jupyter notebooks |
| 105 | +------------------------ |
| 106 | + |
| 107 | +These two notebooks are complete, extended examples that illustrate reading from ODM2 databases and using the resulting data and metadata. They use SQLite ODM2 file databases that can be `downloaded here <https://github.com/ODM2/ODM2PythonAPI/tree/master/Examples/data>`_. |
| 108 | +A conda environment to run these notebooks can be created with the conda environment file |
| 109 | +`clientenvironment.yml <https://github.com/ODM2/ODM2PythonAPI/blob/master/Examples/clientenvironment.yml>`_. |
| 110 | + |
| 111 | +1. `WaterQualityMeasurements_RetrieveVisualize.ipynb <https://github.com/ODM2/ODM2PythonAPI/blob/master/Examples/WaterQualityMeasurements_RetrieveVisualize.ipynb>`_ |
| 112 | + |
| 113 | +2. `TimeSeries_RetrieveVisualize.ipynb <https://github.com/ODM2/ODM2PythonAPI/blob/master/Examples/TimeSeries_RetrieveVisualize.ipynb>`_ |
0 commit comments