Skip to main content

ESY is an ESI wrapper aiming to be simple and pythonic.

Project description

<p><a href=""><img alt="Build Status" src="" /></a>
<a href=""><img alt="Coverage Status" src="" /></a>
<a href=""><img alt="Documentation Status" src="" /></a></p>
<p>There are many options for consuming the ESI web services. ESY aims to be an easy-to-use library with the nuts and
bolts of dealing with an OpenAPI interface abstracted away. </p>
<p>ESY is inspired by Entity's gloriously pythonic <a href="">eveapi</a> library. </p>
<p>The latest stable version of ESY is available from PyPI:
$ pip install esy</code></p>
<p>Documentation is available at <a href=""></a>.</p>
<p>For documentation of the various ESI routes, ESY also provides a
<a href="">terse list</a> of their parameters and return types. Further
information can be explored at the main <a href="">ESI documentation site</a></p>
<p>To use ESI, first initialize a client:</p>
from esy.client import ESIClient
client = ESIClient.get_client('my-user-agent')</code></p>
<p>The client can take a second or two to initialize, as the swagger specification is downloaded and parsed. To speed this
up, you can download the specification locally:</p>
$ curl -o swagger.json</code></p>
<p>Then initialize the client using the local file:</p>
import json
from esy.client import ESIClient</p>
<p>with open('swagger.json', 'r') as spec_file:
spec = json.load(spec_file)
client = ESIClient.get_client('my-user-agent', spec=spec)
<p>For production instances, keeping the spec in <a href="">Redis</a> or some other cache is highly recommended.</p>
<h3>Calling ESI routes</h3>
<p>Once your client is initialized, you can fetch data:</p>
from esy.client import ESIClient
client = ESIClient.get_client('my-user-agent')</p>
<h1>Get list of alliances</h1>
<p>alliances = client.Alliance.get_alliances()</p>
<h1>Get info on a corporation</h1>
<p>evolution = client.Corporation.get_corporations_corporation_id(corporation_id=144749962)
<p>{'alliance_id': 1727758877,
'ceo_id': 144509256,
'creator_id': 144509256,
'date_founded': datetime.datetime(2003, 7, 30, 8, 33, tzinfo=tzutc()),
'description': 'Those who cannot adapt become victims of Evolution.',
'home_station_id': 60013843,
'member_count': 316,
'name': 'Evolution',
'shares': 1000,
'tax_rate': 0.5,
'ticker': 'EVOL',
'url': '',
'faction_id': None}
<p>For ESI routes which are paginated, ESY will return a <a href="source/modules.html#esy.client.ESIPageGenerator">ESIPageGenerator</a> which is a generator yielding the
native data type of the route. </p>
<h1>Get paginated asset list</h1>
<p>swag = client.Corporation.get_corporations_corporation_id_assets(corporation_id=144749962,
_token='esi token')</p>
<h1>swag is an ESIPageGenerator, implementing the generator interface</h1>
<h1>Loop through it to get the asset pages</h1>
<p>for page in swag: # Returns a list of assets
for asset in page: # Asset dict
# 22457
# 16074150552
<p>ESY does not implement caching itself, but supports using a cache through a cache proxy object. The proxy needs
to implement the following interface:</p>
class Cache(object): <br />
def get(self, key: int) -&gt; object:
<pre><code>def set(self, key: int, data: object, cached_until: datetime.datetime):

def __contains__(self, item: object) -&gt; bool:
<h3>Authentication and devel mode</h3>
<p>ESY can handle the authentication flow for you:</p>
from esy.auth import ESIAuthenticator</p>
<p>auth = ESIAuthenticator()
refresh_token, access_token = auth.verify_authorization_code('authorization code from esi',
'your client ID',
'your secret key')</p>
{'CharacterID': 941287462,
'CharacterName': 'Vittoros',
'ExpiresOn': '2018-06-11T19:01:15.182864Z',
'Scopes': ' ',
'TokenType': 'Character',
'CharacterOwnerHash': '<strong><em>*</em></strong>***'}</p>
<p>new_access_token = auth.get_access_token(refresh_token,
'your client ID',
'your secret key')</p>
'your client ID',
'your secret key')</p>
'your client ID',
'your secret key',
<p>To help developers getting started without having to implement the entire authentication
workflow, ESY also implements an ad-hoc web server to get you refresh tokens. You can use
it directly in the python prompt to do some API exploration or you can use it in your tests
to produce refresh or access tokens for testing your ESI calls.</p>
<p>First, create a new application at <a href=""></a>
with callback URL set to http://localhost:8000 or whichever address and port you'll be
running the devel server.</p>
import esy.devel</p>
<h1>get_authorization_code has many parameters, but for basic usage:</h1>
<p>auth_code = esy.devel.get_authorization_code(client_id='your client ID',
callback_url='your callback URL',
scopes='your space-delimited scopes')</p>
<h1>This will start the web server in the background (per-default listening on localhost:8000)</h1>
<h1>and print the login URL on stdout. After authenticating in your browser, the web server</h1>
<h1>will get redirect from the SSO with the authorization code, then return that.</h1>
<h1>For situations where you are not able to reach the network where you are running ESY,</h1>
<h1>you can also use CLI login:</h1>
<p>auth_code = esy.devel.get_authorization_code(cli_login=True,
client_id='your client ID',
callback_url='your callback URL',
scopes='your space-delimited scopes')</p>
<h1>This will prompt for username and password, then let you pick a character.</h1>
<h1>If you are running tests, you can also supply username, password and character_id as</h1>
<h1>keyword arguments to get_authorization_code, in addition to cli_login=True. This will</h1>
<h1>automate the entire flow. Remember to revoke your tokens afterwards and for bob's sake;</h1>
<h1>don't display your username and/or password!</h1>
<h1>After getting the authorization code, you can get the tokens:</h1>
<p>refresh_token, access_token = esy.devel.verify_authorization_code(auth_code,
client_id='your client ID',
secret_key='your secret key')</p>
<h1>Character info</h1>
<p>char_info = esy.devel.verify_access_token(access_token)</p>
<h1>Get your swag</h1>
<p>from esy.client import ESIClient
client = ESIClient.get_client('your-user-agent')
assets = client.Assets.get_characters_character_id_assets(
character_id=char_info.get('CharacterId'), _token=access_token)</p>
<p>for page in assets:
<p>The devel mode will use parameters from environment settings, if present:</p>
<p>Parameter | Environment setting | Default
---| --- | ---
CALLBACK_URL | ESY_CALLBACK_URL | http://localhost:8000
<p>ESY uses the <a href="">Bravado</a> OpenAPI library to parse the ESI swagger schema and create
an usable interface. The purpose of creating a custom wrapper of Bravado for ESI, is to make the interface a bit more
user friendly. Pagination is handled automatically by returning generators for any route which accepts a page
parameter, while non-paginated data is handled in their native data type. Tokens can be set per-call, instead of
per-client, allowing for using headers and still getting data for many tokens without the ned to reinitialize the client.</p>
<p>The authentication flow uses <a href="">requests-oauthlib</a>.</p>

Project details

Download files

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

Files for esy, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size esy-1.1.0-py2.py3-none-any.whl (16.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size esy-1.1.0.tar.gz (15.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page