Skip to main content

A Python library to access your sharesight portfolio information

Project description

Sharesight API

API to interface with Sharesight's v2 API

  • Supports PUSH, PUT, DELETE and GET requests
  • Only supports a single portfolio request per instance of the API

How to use

See the pytest.py file for an example

This whole thing is designed to be asynchronous

Added support for refresh token, no need to feed in clientID, clientSecret or authCode if token file exists

This API was designed to handle all the tokens requirements, but you are able to manage it yourself, removing the need to use get_token_data() and validate_token(), by passing the access token into get_api_request().

How to install

Do pip install SharesightAPI

How to test using pytest.py

To test the API, run the pytest.py file, with the variables in blank filled in, it will update specific post specific data points to the console, and a json file with the output will be made

How to get API token

Read here (you may need to get in contact with them over live chat)

Input/Output

To start, call and assign (like this)

sharesight = SharesightAPI.SharesightAPI(client_id, client_secret, authorization_code, redirect_uri, token_url, api_url_base, use_token_file, True, token_file_name)

Sharesight has some recommendations for defaults as seen here:

I have assumed some things (if left blank):

  • token_file = 'sharesight_token.txt'
  • debugging = False
  • useEdge = False (Edge is the developer testing profile/account, it has a different root URL)

Setting token_file to be 'HA.txt' will append the client ID to sharesight_token. eg: sharesight_token_4123213214123.txt

Then; to get the existing data contained within the token file (optional), run this to get the values and store it within the constructor:

await sharesight.get_token_data()

To check the currently loaded token, run the .validate_token() call, if it will return if the token has passed, failed and why. and will store the token in a .txt file

This returns the current access_token, which can be passed in to use in API calls

access_token = await sharesight.validate_token()

To make an API call (get): call .get_api_request(endpoint, endpoint_list_version), making the endpoint being a list of the API version, the call URL, and the params if applicable. It will return a dictionary with the response. You are able to parse through the access_token, otherwise it will default to the current access token in the constructor.

example: await sharesight.get_api_request(["v2","portfolios", None])

or

example: await sharesight.get_api_request(["v2","portfolios", None], access_token)

To make an API call (post): call .post_api_request, with the addition of parsing in a payload JSON to post

example: await sharesight.post_api_request(["v2","portfolios"], "{ "portfolio": { "name": "My new Portfolio"}})

you can see a full list of v2 endpoints here, and v3 endpoints here (including examples)

Call delete_token() to remove the Token file from the instance (will cause a new auth_code to be needed)

To close the connection, call close()

Manual Token Handling

This is an alternative to saving the token in the current directory, this allows you to handle all the token functions.

To store your own token data elsewhere, call return_token() to gets the currently saved token information, which can be called after the token is validated (see pytest for more details)

(This removes the need for save_token and load_token methods, as you'll be handling it, but the token will still be refreshed)

Token data is returned like this:

{ 'auth_code': 12345, 'access_token': 12345, 'token_expiry': 12345, 'refresh_token': 12345 }

To then inject your token into the API, you need to call inject_token(token_data) where token_data is the token, in the same format as above

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

sharesightapi-1.1.18.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SharesightAPI-1.1.18-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file sharesightapi-1.1.18.tar.gz.

File metadata

  • Download URL: sharesightapi-1.1.18.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for sharesightapi-1.1.18.tar.gz
Algorithm Hash digest
SHA256 46bb2587c977fef2a51da5a5b162f06cd06f6b3ce047f06e240208830ef01876
MD5 c2d3b31646fea05032025e01daf2a976
BLAKE2b-256 62c1dbdc51eceef7973dbd579134877546a35435b40cb1837a891232bad0c594

See more details on using hashes here.

File details

Details for the file SharesightAPI-1.1.18-py3-none-any.whl.

File metadata

  • Download URL: SharesightAPI-1.1.18-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for SharesightAPI-1.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 29b53659c33074167ad4fa48c17616ee66391ab950266ca27142f255960cc82b
MD5 080b385cbed52b6e3eb02d134ad4030e
BLAKE2b-256 82c1aea5d97672f5a409374a90636f0f660784643d29a535989c9ced75db3741

See more details on using hashes here.

Supported by

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