Skip to main content

EVE ESI API access tool

Project description

Preston

CI codecov Python version Code style: black License

Preston is a Python library for accessing EVE Online's ESI API.

Quick links

Installation

From pip:

pip install preston

Initialization

from preston import Preston

preston = Preston()

There are values that you can pass to __init__ as kwargs; those are detailed in the docstring for the class.

Usage

There are 3 main things that Preston does:

  1. Unauthenticated calls to ESI
  2. User authentication
  3. Authenticated calls to ESI for that user

For #1, all you need to do is initialize a Preston object and make the call:

preston = Preston(
    user_agent='some_user_agent'
)

data = preston.get_op('get_characters_character_id', character_id=91316135)
# ...

You should always include a good user_agent.

Additionally, a post_op method exists, that takes a dictionary (instead of **kwargs) and another parameter; the former is used like above, to satisfy the URL parameters, and the latter is sent to the ESI endpoint as the payloadd.

For #2, there are 2 methods that you'll need, get_authorize_url and authenticate, and several __init__ kwargs.

preston = Preston(
    user_agent='some_user_agent',
    client_id='something',
    client_secret='something',
    callback_url='something',
    scope='maybe_something',
)

You can find the last 4 values in your application on the EVE Dev site.

When you have a Preston instance constructed like this, you can make the call to get_authorize_url:

preston.get_authorize_url()
# https://login.eveonline.com/oauth/...

This is the URL that your user needs to visit and complete the flow. They'll be redirected to your app's callback URL, so you have to be monitoring that.

When you get their callback, take the code paramter from the URL and pass it to authenticate:

auth = preston.authenticate('their_code_here')

Note the return variable and it's reassignment: this method returns a new instance, with the corresponding variables and headers setup for authenticated ESI calls.

Finally for #3, having followed the steps above, you just make calls like previously, but you can do so to the authenticated-only endpoints. Make sure that if you're calling an endpoint that requires a specific scope, your app on EVE Devs has that scoped added and you've supplied it to the Preston initialization.

Resuming authentication

If your app uses scopes, it'll receive a refresh_token alongside the access_token. The access token, per usual, only lasts 20 minutes before it expires. In this situation, the refresh token can be used to get a new access token. If your Preston instance has a refresh token, this will be done automatically when the access token expires.

You can also get this refresh token from the Preston instance with token = preston.refresh_token. This can be then stored somewhere (securely) and used again later by passing the token to Preston's constructor:

preston = Preston(
    user_agent='some_user_agent',
    client_id='something',
    client_secret='something',
    callback_url='something',
    scope='maybe_something',
    refresh_token='your_token_here'
)

Preston will take the refresh token and attempt to get a new access token from it.

On that note, you can also pass the access_token to a new Preston instance, but there's less of a use case for that, as either you have an app with scopes, yielding a refresh token, or an authentication-only app where you only use the access token to verify identity and some basic information before moving on.

Developing

Building

Requirements

  • Git
  • Poetry
  • Python 3.8+

Steps

git clone https://github.com/Celeo/preston
cd preston
poetry install

Running tests

No coverage poetry run pytest
Coverage printout poetry run pytest --cov=preston
Coverage report poetry run pytest --cov=preston --cov-report=html

License

Licensed under MIT (LICENSE).

Contributing

PRs are welcome. Please follow PEP8 (I'm lenient on E501) and use Google-style docstrings.

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

preston-4.6.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

preston-4.6.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file preston-4.6.0.tar.gz.

File metadata

  • Download URL: preston-4.6.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.12 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for preston-4.6.0.tar.gz
Algorithm Hash digest
SHA256 6a504bf42f59de5a7ad32620a643fa88dfa50b8b4baf1bc10a5856e01b8e18be
MD5 3391ce6c3283bf644b1131d55c3d78a8
BLAKE2b-256 3c325427701afb8d06210bac7a39037fc0059ade523cf06c48ced9871e37692a

See more details on using hashes here.

File details

Details for the file preston-4.6.0-py3-none-any.whl.

File metadata

  • Download URL: preston-4.6.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.12 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for preston-4.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07377963cf91c210b3ae682d6aa1b6628c70dbfd7bf7e9d93f5e4bfeb6164b6d
MD5 814c2bee33357528fffc2799de761019
BLAKE2b-256 a36ad42a2321731df77cfa94a98ea0ea5e520b8712544ed98375ea21e4703e99

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