Code Monkey home page Code Monkey logo

hud-ai-python's Introduction

HUD.ai Python Client

Build Status PyPI PyPI License

The HUD.ai Python Client provides an easy to use wrapper to interact with the HUD.ai API in python applications.

You must first acquire a HUD.ai secret key before you can use this module.

Installation

pip install hudai

Usage

from hudai import Client as HudAiClient

hud_ai = HudAiClient(
    client_id='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    client_secret='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
)

hud_ai.companies.list()

hud_ai.articles.fetch('17787d76-4198-4775-a49a-b3581c37a482')

Parameters

Parameter Usage Example
client_id* Registered Client ID '46ef9d9b-89a9-4fd2-84cf-af6de31f2618'
client_secret Registered Client Secret '59170c3e-e2c9-4244-92d8-c3595d4af325'
base_url Specify an alternate server to request resources from 'https://stage.api.hud.ai/v1'
auth_url Specify an alternate server to request auth tokens from 'https://stage.accounts.hud.ai'
redirect_uri Path to redirect auth requests to (required for #get_authorize_uri) 'https://app.example.com/oauth/callbacks/hud-ai'

Client Auth Flow

In order to access HUD.ai data on a user's behalf, they must authorize you to do so. This requires 3 steps.

First, send them to the authorization URL

from flask import Flask, redirect, url_for
from hudai import Client as HudAiClient

app = Flask(__name__)

hud_ai = HudAiClient(
    client_id='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    client_secret='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    redirect_uri='https://app.example.com/oauth/callbacks/hud-ai'
)

@app.route('/oauth/authorize/hud-ai')
def hud_ai_authorization():
    return redirect(hud_ai.get_authorize_uri(), code=302)

Now the user will be presented with a dialog screen where they can accept or deny your request. The auth server will redirect back to your app in either case.

Finally, parse the response and get the code and attach it to the client. The code will be exchanged before the next request is made.

@app.route('/oauth/callbacks/hud-ai')
def hud_ai_callback():
    code = request.args.get('code')
    hud_ai.set_auth_code(code)

client.get_authorize_uri()

NOTE: This method requires redirect_uri

Returns a URL to direct users to to authorize your application to act on their behalf. You will need to handle the redirect that includes the code

client.set_auth_code(code)

Store the code for future exchange for an auth token

client.refresh_tokens()

Attempts to ensure that the client has valid auth tokens.

  • Refreshes known expired tokens
  • Exchanges auth codes for access tokens
  • Exchanges client ID/secret for app access tokens

Resources

Notes

  • * and bolded Type indicates required param
  • Params indicated with ? are optional keyword params
  • Date types are automatically converted to/from standard DateTime objects
  • All list resources are paginated to 50/request, with page being 0-indexed (e.g. page=3 will get you the fourth page)
Entity Method Base
Article client.articles
ArticleHighlights client.article_highlights
ArticleKeyTerm client.article_key_terms
ArticleTag client.article_tags
ArticleGeography client.article_geographies
Company client.companies
CompanyEvent client.company_events
CompanyIndustry client.company_industries
CompanyKeyTerm client.company_key_terms
Domain client.domains
Industry client.industries
KeyTerm client.key_terms
Person client.people
PersonKeyTerm client.person_key_terms
PersonQuote client.person_quotes
SystemEvent client.system_events
SystemTask client.system_tasks
TextCorpus client.text_corpora
User client.users
UserCompany client.user_companies
UserContact client.user_contacts
UserDigestSubscription client.user_digest_subscriptions
UserKeyTerm client.user_key_terms

Deployment

Deploys occur automatically via Travis-CI on tagged commits that build successfully. Should you need to manually build the project, follow these steps:

# Install twine to prevent your password from being set in plaintext
pip install twine
# Build the package
python setup.py sdist
# Upload via twine
twine upload dist/hudai-NEW_VERSION_HERE.tar.gz

hud-ai-python's People

Contributors

christophe-williams avatar chriswynnyk avatar jbender avatar k-niu avatar njgerner avatar peterfoundry avatar schmod avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hud-ai-python's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.