looker-sdk


Namelooker-sdk JSON
Version 24.8.0 PyPI version JSON
download
home_pagehttps://pypi.python.org/pypi/looker_sdk
SummaryLooker REST API
upload_time2024-05-07 19:37:06
maintainerNone
docs_urlNone
authorLooker Data Sciences, Inc.
requires_python>=3.6
licenseMIT
keywords looker looker api looker_sdk looker api 4.0
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ===========
Looker SDK
===========

The Looker SDK for Python provides a convenient way to communicate with the
Looker API available on your Looker server. The library requires python3.6+
and is annotated using the typing module.

The SDK uses a plug-in architecture (also known as dependency injection) for
initializing that supports run-time specific transports (currently only
`RequestsTransport`) and different approaches for managing API authentication
(`AuthSession` and `OAuthSession`). The methods and models are generated from
the Looker API spec by a new code generator developed at Looker.

Please `report any issues <https://github.com/looker-open-source/sdk-codegen/issues>`_
encountered, and indicate the SDK language in the report.

Basic Usage
===========
.. code-block:: python

    import looker_sdk

    # For this to work you must either have set environment variables or created a looker.ini as described below in "Configuring the SDK"
    sdk = looker_sdk.init40()  # or init31() for the older v3.1 API
    my_user = sdk.me()

    # output can be treated like a dictionary
    print(my_user["first_name"])
    # or a model instance (User in this case)
    print(my_user.first_name)

    # input methods can take either model instances like WriteUser
    sdk.create_user(
        body=looker_sdk.models.WriteUser(first_name="Jane", last_name="Doe")
    )
    # or plain dictionaries
    sdk.create_user(body={"first_name": "Jane", "last_name": "Doe"})

Full tutorial
=============
Go from installation all the way to creating a functional micro-application in this 20-30 minute interactive tutorial.

*This tutorial is hosted in Google Colaboratory, an interactive online notebook. You can follow along right in the notebook by clicking the button below.*

.. image:: https://colab.research.google.com/assets/colab-badge.svg
   :target: https://colab.research.google.com/github/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb


Sample project setup
====================

Install python 3.8. We highly recommend using
`pyenv <https://github.com/pyenv/pyenv#installation>`_ to install
different versions of python. Mac users should use
`homebrew <https://brew.sh/>`_ to install pyenv:

.. code-block:: bash

    brew install pyenv

Linux users should use

.. code-block:: bash

    curl https://pyenv.run | bash

Put this in your shell configuration script:

.. code-block:: bash

    export PATH=$PATH:$HOME/.pyenv/bin
    eval "$(pyenv init --path)"
    eval "$(pyenv init -)"
    eval "$(pyenv virtualenv-init -)"

Follow the **remaining steps 3 - 5** of
https://github.com/pyenv/pyenv#basic-github-checkout otherwise your python3.8
installation may break.

Now you're ready to install python 3.8:

.. code-block:: bash

    pyenv install 3.8.2

We'll use `pipenv <https://docs.pipenv.org/en/latest/#install-pipenv-today>`_
(fantastic virtualenv manager) to manage project dependencies.

.. code-block:: bash

    brew install pipenv

Create a project directory

.. code-block:: bash

    mkdir looker-sdk-example

Set python3.8 as the base interpreter for this directory

.. code-block:: bash

    cd looker-sdk-example/
    pyenv local 3.8.2

Install looker_sdk using pipenv

.. code-block:: bash

    pipenv --python 3.8.2 install --pre looker_sdk


Configuring the SDK
===================

The SDK supports configuration through

1. an ``.ini`` file on disk
2. `setting environment variables <https://github.com/looker-open-source/sdk-codegen#environment-variable-configuration>`_
3. providing your own implementation of the ApiSettings class

. The latter override the former.

**Note**: The ``.ini`` configuration for the Looker SDK is a sample
implementation intended to speed up the initial development of python
applications using the Looker API. See this note on
`Securing your SDK Credentials <https://github.com/looker-open-source/sdk-codegen/blob/main/README.md#securing-your-sdk-credentials>`_
for warnings about using ``.ini`` files that contain your
API credentials in a source code repository or production environment.

In order to configure the SDK client, create a "looker.ini" file to reference
during ``client.setup()``

example file:

::

    [Looker]
    # Base URL for API. Do not include /api/* in the url. If hosted on GCP, remove the :19999 leaving just https://your.cloud.looker.com
    base_url=https://your.looker.com:19999
    # API 3 client id
    client_id=YourClientID
    # API 3 client secret
    client_secret=YourClientSecret
    # Set to false if testing locally against self-signed certs. Otherwise leave True
    verify_ssl=True

**Note**: If the application using the Looker SDK is going to be committed to a version control system, be sure to
**ignore** the ``looker.ini`` file so the API credentials aren't unintentionally published.

For any ``.ini`` setting you can use an environment variable instead. It takes the form of
``LOOKERSDK_<UPPERCASE-SETTING-FROM-INI>`` e.g. ``LOOKERSDK_CLIENT_SECRET``

A final option is to provide your own implementation of the ApiSettings class. It is easiest to subclass ``api_settings.ApiSettings`` and override the ``read_config`` function (don't forget a call to ``super().read_config()`` if appropriate, Example below). However, at a minimum your class must implement the `api_settings.PApiSettings` protocol.


.. code-block:: python

    import os
    import looker_sdk
    from looker_sdk import api_settings

    class MyApiSettings(api_settings.ApiSettings):
        def __init__(self, *args, **kw_args):
            self.my_var = kw_args.pop("my_var")
            super().__init__(*args, **kw_args)

        def read_config(self) -> api_settings.SettingsConfig:
            config = super().read_config()
            # See api_settings.SettingsConfig for required fields
            if self.my_var == "foo":
                config["client_id"] = os.getenv("FOO_CLIENT")
                config["client_secret"] = os.getenv("FOO_SECRET")
            else:
                config["client_id"] = os.getenv("BAR_CLIENT")
                config["client_secret"] = os.getenv("BAR_SECRET")
            return config

    sdk = looker_sdk.init40(config_settings=MyApiSettings(my_var="foo"))
    ...


Code example
============
`See many python sdk examples in our examples repo <https://github.com/looker-open-source/sdk-codegen/tree/main/examples/python>`_

Changelog
============
`Located in our github repo <https://github.com/looker-open-source/sdk-codegen/tree/main/python/CHANGELOG.md>`_

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.python.org/pypi/looker_sdk",
    "name": "looker-sdk",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "Looker, Looker API, looker_sdk, Looker API 4.0",
    "author": "Looker Data Sciences, Inc.",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/b0/c4/98b3c7872d68e075bad04778c152264ce2fdcead6ac367700a22551d27e3/looker_sdk-24.8.0.tar.gz",
    "platform": null,
    "description": "===========\nLooker SDK\n===========\n\nThe Looker SDK for Python provides a convenient way to communicate with the\nLooker API available on your Looker server. The library requires python3.6+\nand is annotated using the typing module.\n\nThe SDK uses a plug-in architecture (also known as dependency injection) for\ninitializing that supports run-time specific transports (currently only\n`RequestsTransport`) and different approaches for managing API authentication\n(`AuthSession` and `OAuthSession`). The methods and models are generated from\nthe Looker API spec by a new code generator developed at Looker.\n\nPlease `report any issues <https://github.com/looker-open-source/sdk-codegen/issues>`_\nencountered, and indicate the SDK language in the report.\n\nBasic Usage\n===========\n.. code-block:: python\n\n    import looker_sdk\n\n    # For this to work you must either have set environment variables or created a looker.ini as described below in \"Configuring the SDK\"\n    sdk = looker_sdk.init40()  # or init31() for the older v3.1 API\n    my_user = sdk.me()\n\n    # output can be treated like a dictionary\n    print(my_user[\"first_name\"])\n    # or a model instance (User in this case)\n    print(my_user.first_name)\n\n    # input methods can take either model instances like WriteUser\n    sdk.create_user(\n        body=looker_sdk.models.WriteUser(first_name=\"Jane\", last_name=\"Doe\")\n    )\n    # or plain dictionaries\n    sdk.create_user(body={\"first_name\": \"Jane\", \"last_name\": \"Doe\"})\n\nFull tutorial\n=============\nGo from installation all the way to creating a functional micro-application in this 20-30 minute interactive tutorial.\n\n*This tutorial is hosted in Google Colaboratory, an interactive online notebook. You can follow along right in the notebook by clicking the button below.*\n\n.. image:: https://colab.research.google.com/assets/colab-badge.svg\n   :target: https://colab.research.google.com/github/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb\n\n\nSample project setup\n====================\n\nInstall python 3.8. We highly recommend using\n`pyenv <https://github.com/pyenv/pyenv#installation>`_ to install\ndifferent versions of python. Mac users should use\n`homebrew <https://brew.sh/>`_ to install pyenv:\n\n.. code-block:: bash\n\n    brew install pyenv\n\nLinux users should use\n\n.. code-block:: bash\n\n    curl https://pyenv.run | bash\n\nPut this in your shell configuration script:\n\n.. code-block:: bash\n\n    export PATH=$PATH:$HOME/.pyenv/bin\n    eval \"$(pyenv init --path)\"\n    eval \"$(pyenv init -)\"\n    eval \"$(pyenv virtualenv-init -)\"\n\nFollow the **remaining steps 3 - 5** of\nhttps://github.com/pyenv/pyenv#basic-github-checkout otherwise your python3.8\ninstallation may break.\n\nNow you're ready to install python 3.8:\n\n.. code-block:: bash\n\n    pyenv install 3.8.2\n\nWe'll use `pipenv <https://docs.pipenv.org/en/latest/#install-pipenv-today>`_\n(fantastic virtualenv manager) to manage project dependencies.\n\n.. code-block:: bash\n\n    brew install pipenv\n\nCreate a project directory\n\n.. code-block:: bash\n\n    mkdir looker-sdk-example\n\nSet python3.8 as the base interpreter for this directory\n\n.. code-block:: bash\n\n    cd looker-sdk-example/\n    pyenv local 3.8.2\n\nInstall looker_sdk using pipenv\n\n.. code-block:: bash\n\n    pipenv --python 3.8.2 install --pre looker_sdk\n\n\nConfiguring the SDK\n===================\n\nThe SDK supports configuration through\n\n1. an ``.ini`` file on disk\n2. `setting environment variables <https://github.com/looker-open-source/sdk-codegen#environment-variable-configuration>`_\n3. providing your own implementation of the ApiSettings class\n\n. The latter override the former.\n\n**Note**: The ``.ini`` configuration for the Looker SDK is a sample\nimplementation intended to speed up the initial development of python\napplications using the Looker API. See this note on\n`Securing your SDK Credentials <https://github.com/looker-open-source/sdk-codegen/blob/main/README.md#securing-your-sdk-credentials>`_\nfor warnings about using ``.ini`` files that contain your\nAPI credentials in a source code repository or production environment.\n\nIn order to configure the SDK client, create a \"looker.ini\" file to reference\nduring ``client.setup()``\n\nexample file:\n\n::\n\n    [Looker]\n    # Base URL for API. Do not include /api/* in the url. If hosted on GCP, remove the :19999 leaving just https://your.cloud.looker.com\n    base_url=https://your.looker.com:19999\n    # API 3 client id\n    client_id=YourClientID\n    # API 3 client secret\n    client_secret=YourClientSecret\n    # Set to false if testing locally against self-signed certs. Otherwise leave True\n    verify_ssl=True\n\n**Note**: If the application using the Looker SDK is going to be committed to a version control system, be sure to\n**ignore** the ``looker.ini`` file so the API credentials aren't unintentionally published.\n\nFor any ``.ini`` setting you can use an environment variable instead. It takes the form of\n``LOOKERSDK_<UPPERCASE-SETTING-FROM-INI>`` e.g. ``LOOKERSDK_CLIENT_SECRET``\n\nA final option is to provide your own implementation of the ApiSettings class. It is easiest to subclass ``api_settings.ApiSettings`` and override the ``read_config`` function (don't forget a call to ``super().read_config()`` if appropriate, Example below). However, at a minimum your class must implement the `api_settings.PApiSettings` protocol.\n\n\n.. code-block:: python\n\n    import os\n    import looker_sdk\n    from looker_sdk import api_settings\n\n    class MyApiSettings(api_settings.ApiSettings):\n        def __init__(self, *args, **kw_args):\n            self.my_var = kw_args.pop(\"my_var\")\n            super().__init__(*args, **kw_args)\n\n        def read_config(self) -> api_settings.SettingsConfig:\n            config = super().read_config()\n            # See api_settings.SettingsConfig for required fields\n            if self.my_var == \"foo\":\n                config[\"client_id\"] = os.getenv(\"FOO_CLIENT\")\n                config[\"client_secret\"] = os.getenv(\"FOO_SECRET\")\n            else:\n                config[\"client_id\"] = os.getenv(\"BAR_CLIENT\")\n                config[\"client_secret\"] = os.getenv(\"BAR_SECRET\")\n            return config\n\n    sdk = looker_sdk.init40(config_settings=MyApiSettings(my_var=\"foo\"))\n    ...\n\n\nCode example\n============\n`See many python sdk examples in our examples repo <https://github.com/looker-open-source/sdk-codegen/tree/main/examples/python>`_\n\nChangelog\n============\n`Located in our github repo <https://github.com/looker-open-source/sdk-codegen/tree/main/python/CHANGELOG.md>`_\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Looker REST API",
    "version": "24.8.0",
    "project_urls": {
        "Homepage": "https://pypi.python.org/pypi/looker_sdk"
    },
    "split_keywords": [
        "looker",
        " looker api",
        " looker_sdk",
        " looker api 4.0"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e9f33961b8884ea8a924a37f0c17c2b102f604527069a6c105beae886964c30e",
                "md5": "7ba8f86465286c974a314c8442cb20e4",
                "sha256": "a5a0cbef9706aeaff777aaf2951d9e3ebe51959498d0f83422d6690fd64a011c"
            },
            "downloads": -1,
            "filename": "looker_sdk-24.8.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7ba8f86465286c974a314c8442cb20e4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 225951,
            "upload_time": "2024-05-07T19:37:02",
            "upload_time_iso_8601": "2024-05-07T19:37:02.602526Z",
            "url": "https://files.pythonhosted.org/packages/e9/f3/3961b8884ea8a924a37f0c17c2b102f604527069a6c105beae886964c30e/looker_sdk-24.8.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0c498b3c7872d68e075bad04778c152264ce2fdcead6ac367700a22551d27e3",
                "md5": "716f95c42c2b88f3e40a1a8f3a5833a7",
                "sha256": "e7d4fdb24e0638d84f6bc1330afe70ef9dd9d1c5961a5171e6661c093a0c4360"
            },
            "downloads": -1,
            "filename": "looker_sdk-24.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "716f95c42c2b88f3e40a1a8f3a5833a7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 204381,
            "upload_time": "2024-05-07T19:37:06",
            "upload_time_iso_8601": "2024-05-07T19:37:06.479337Z",
            "url": "https://files.pythonhosted.org/packages/b0/c4/98b3c7872d68e075bad04778c152264ce2fdcead6ac367700a22551d27e3/looker_sdk-24.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-07 19:37:06",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "looker-sdk"
}
        
Elapsed time: 0.28821s