File: advanced.rst

package info (click to toggle)
python-chemspipy 2.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 288 kB
  • sloc: python: 1,125; makefile: 14
file content (41 lines) | stat: -rw-r--r-- 1,318 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
.. _advanced:

Advanced
========

Keep Your API Key Secret
------------------------

Be careful not to include your API key when sharing code. A simple way to ensure this doesn't happen by accident is to
store your API key as an environment variable that can be specified in your `.bash_profile` or `.zshrc` file::

    export CHEMSPIDER_API_KEY=<YOUR-API-KEY>

This can then be retrieved in your scripts using ``os.environ``::

    >>> api_key = os.environ['CHEMSPIDER_API_KEY']
    >>> cs = ChemSpider(api_key)

Specify a User Agent
--------------------

As well as using your API key, it is possible to identify your program to the ChemSpider servers using a User
Agent string.

You can specify a custom User Agent through ChemSpiPy through the optional ``user_agent`` parameter to the ChemSpider
class::

    >>> from chemspipy import ChemSpider
    >>> cs = ChemSpider('<YOUR-API-KEY>', user_agent='My program 1.3, ChemSpiPy 2.0.0, Python 3.6')

Logging
-------

ChemSpiPy can generate logging statements if required. Just set the desired logging level::

    import logging
    logging.basicConfig(level=logging.DEBUG)

The logger is named 'chemspipy'. There is more information on logging in the `Python logging documentation`_.

.. _`Python logging documentation`: https://docs.python.org/3/howto/logging.html