Package: preston
PrestonPreston is a Python library for accessing EVE Online's ESI API.Quick linksEVE ESI:https://esi.evetech.netEVE developers:https://developers.eveonline.comInstallationFrompip:pipinstallprestonInitializationfromprestonimportPrestonpreston=Preston()There are values that you can pass to__init__as kwargs; those are detailed in the docstring for the class.UsageThere are 3 main things that Preston does:Unauthenticated calls to ESIUser authenticationAuthenticated calls to ESI for that userFor #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 gooduser_agent.Additionally, apost_opmethod 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_urlandauthenticate, 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 theEVE Dev site.When you have a Preston instance constructed like this, you can make the call toget_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 toauthenticate:auth=preston.authenticate('their_code_here')Note the return variable and it's reassignment: this method returns anewinstance, 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 authenticationIf your app uses scopes, it'll receive arefresh_tokenalongside theaccess_token. The access token, per usual, only lasts 20 minutes before it expires. In this situation,
the refresh token can be used to get anewaccess 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 withtoken = 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 theaccess_tokento 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.DevelopingBuildingRequirementsGitPoetryPython 3.8+Stepsgitclonehttps://github.com/Celeo/prestoncdpreston
poetryinstallRunning testsNo coveragepoetry run pytestCoverage printoutpoetry run pytest --cov=prestonCoverage reportpoetry run pytest --cov=preston --cov-report=htmlLicenseLicensed under MIT (LICENSE).ContributingPRs are welcome. Please follow PEP8 (I'm lenient on E501) and useGoogle-style docstrings.