Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
namara-python / METADATA
Size: Mime:
Metadata-Version: 2.1
Name: namara-python
Version: 1.0.5
Summary: A simple interface for working with Namara in Python
Home-page: https://thinkdataworks.com
Author: Thinkdata Works
Author-email: info@thinkdataworks.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.6
Requires-Dist: protobuf (==3.11.3)
Requires-Dist: requests (==2.23.0)
Requires-Dist: python-dotenv (==0.12.0)
Requires-Dist: pandas

# namara-python
Python SDK for Namara API and namara-pandas

## Installation
You need Python 3.7 or above and the package manager [pip](https://pip.pypa.io/en/stable/) to install dependencies.
```bash
pip3 install -r requirements.txt
```

Docker is used in this repo only for integration with Jenkins CI, you don't need to run through docker at all.

## Authorization
Can read API key from environment variables or directly passed into Client.
The Namara API urls are also read from environement variables

```syntax=ruby
export NAMARA_API_KEY=my_namara_api_key
export NAMARA_API_URL=https://api.ee-dev.namara.io
export NAMARA_AUTH_URL=https://account.ee-dev.namara.io
```


In Python
```syntax=ruby
from namara_python.client import Client

client = Client()
```

*OR*

Pass them in directly
```
from namara_python.client import Client

client = Client(
    api_key='my_namara_api_key', 
    auth_url='https://account.ee-dev.namara.io',
    api_url='https://api.ee-dev.namara.io'
)
```

The `client` object is now ready to make requests to Namara API

## Environment variables
You can create a `.env` file to manage environment variables more easily, namara-python will read those.

in `.env`

```syntax=ruby
export NAMARA_API_KEY=my_namara_api_key
export NAMARA_API_URL=https://api.ee-dev.namara.io
export NAMARA_AUTH_URL=https://account.ee-dev.namara.io
```

## Query

You can pass the query statement directly
```
from namara_python.client import Client

c = Client(
    api_key='my_namara_api_key',
    auth_url='https://account.ee-dev.namara.io',
    api_url='https://api.ee-dev.namara.io'
)

res = c.query(statement='SELECT * FROM f78871ca-71f9-4071-859c-7d6ba414972e AS ACM')
print(res)

datasets = c.list_datasets()
print(datasets)
```
The `Query` object is now ready to make NiQL queries directly to Namara Query API

## Development

### Running tests

`make test`

You can run a specific test by marking it in the test file, above the function:

```syntax=ruby
@pytest.mark.only # <- add this
def only_test_to_run():
    ...

```

And then run 

```
make test_only
```

### Static analysis

This project uses Pythons type annotations for some static analysis for types.

Install mypy

```syntax=ruby
pip install mypy
```

To do type checking

```syntax=ruby
mypy --ignore-missing-imports .
```

We skip import checks just becuase mypy doesn't quite work as you would expect for imports, especially third party packages


### Testing code locally

There's scratch file that you could use to import code and quickly test out the sdk.

There's one already called `tester.py`, fill in your api_key and a valid dataset id and your setup to start testing things out!

Run:

```
ipython -i tester.py
```

to get an interactive shell with tester.py code having already been run. 

NOTE: This will error out if you haven't specified your api_key and a proper dataset id (that you have access to) before hand, so dont panic that it failed.
NOTE II: DO NOT check in this file with any credentials, especially api key.


## Pandas extension

Look here: https://github.com/thinkdata-works/namara-python/tree/develop/namara_pandas