Skip to main content

Python SDK for interacting with the NLx API and other affiliated tools

Project description

Installation

Install via pip

pip install nlx-cli

Configuration

You can configure cli settings with a .env file and/or environment variables. The only configuration you will need to modify out of the box is NLX_API_KEY. To list the current active configuration, you can use the config command:

nlx config | jq
{
  "NLX_ENV_PATH": ".env",
  "NLX_SUPPRESS_ENV_NOTICE": true,
  "NLX_LOG_LEVEL": "INFO",
  "NLX_API_KEY": "<redacted>",
  "NLX_API_URL": "https://api.nlxresearchhub.org",
  "NLX_REPORT_HISTORY_STORAGE": "nlx.pickle",
  "NLX_REPORT_DOWNLOAD_DIR": ".reports"
}

Usage

You can use any access methods defined directly by the CLI or you can define a custom runner module. For details on CLI methods, you can run nlx --help.

Custom Runner Module

Custom runner modules allow you to specify a client class and a list of operations to perform with that client class. Custom runner modules must define the following:

  • RUNNER_CLIENT python module style import path to your Client class definition
  • RUNNER_OPS list of operations which will be performed by your client
  • RUNNER_OP_ERROR_HANDLER function which wraps each operation and handles thrown errors

Below is an example of a custom runner module (the current revision of which can be found in ./examples/example_run_config.py). To run this example, copy the contents of the runner into a example_run_config.py in you current working directory and execute the command nlx run example_run_config. To preview the operations that this will run, you can use nlx show_ops example_run_config

"""
This runner will create, await, and download async reports for all job listings
compiled in the years 2017-2022 for Kansas.

You want to place this file in your current working directory or a location that
is importable from your current python path.
"""
import logging

from nlx.helpers import helpers
from nlx.utils.misc import basic_logger

logger = basic_logger(__name__, logging.DEBUG)

# python module style import path of the Client class to be executed by the runner.
RUNNER_CLIENT = "nlx.client.AsyncReport"

# years 2017-2022, inclusive
YEARS = [*range(2017, 2023)]
# Kansas
STATES = ["KS"]

RUNNER_OPS = []
for state in STATES:
    for year in YEARS:
        # generate twelve months of the arguments for start, end, state, auto
        for generated_kwargs in helpers.generate_year_kwargs(year, state=state, auto=True):
            # indicate that the kwargs will be passed to RUNNER_CLIENT.create, e.g.
            # nlx.client.AsyncReport().create(**generated_kwargs)
            RUNNER_OPS.append(("create", generated_kwargs))


def error_handler(func, *args, **kwargs):
    try:
        return func(*args, **kwargs)
    except KeyboardInterrupt:
        raise
    except:  # noqa
        logger.exception(
            f"Something unexpected happened when executing func={func} args={args}, kwargs={kwargs}"
        )


RUNNER_OP_ERROR_HANDLER = error_handler

Programmatic Usage

If custom runner modules don't provide enough flexibility for your use-case, you can always import anything available in the nlx-cli package for use as you see fit.

from nlx.client import AsyncReport

assert AsyncReport().is_authorized

Build & Publish

# asks for credentials
poetry publish --build

# OR
pip install twine
rm -rf ./dist/
poetry build
# uses ~/.pypirc
twine upload -r testpypi dist/*
twine upload -r pypi dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nlx-cli-0.1.5.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

nlx_cli-0.1.5-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file nlx-cli-0.1.5.tar.gz.

File metadata

  • Download URL: nlx-cli-0.1.5.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for nlx-cli-0.1.5.tar.gz
Algorithm Hash digest
SHA256 0d3c4692926d71d90714dc670d7792cfe15966d1af21c32ec3f56e526e20eacf
MD5 7af83cc918d46268e19bbf7ee3130ab5
BLAKE2b-256 1e888e201406a2434e822e8b5758b3005774f940e32170548996ea95a4dc3fc9

See more details on using hashes here.

File details

Details for the file nlx_cli-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: nlx_cli-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for nlx_cli-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 51023e530f3fd09313adb1b77cbc94ed2574962aeaf77f5cfb3ae9448e081990
MD5 aa26d26cb7bd13fd4f09ece77c66fce3
BLAKE2b-256 3108881d56b105825f980faff082b993db3294a5af12f63a95e3f52743fd06d2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page