eveapi2
Sane EVE Online API.
Features
- Not done yet!
- Sane model-like API.
- Python3 only.
- No network layer, you supply the raw XML.
- Timezone aware.
- Directly passable to Django/SQLAlchemy model via dict(alliance)
Installation
With pip:
pip install -r REQUIREMENTS.txt
pip install eveapi2
Manually
git clone https://github.com/lunemec/eveapi2.git
cd eveapi2
pip install -r REQUIREMENTS.txt
python setup.py install
Usage
from eveapi2 import alliance_list
import requests
http_response = requests.get(alliance_list.url)
if http_response.status_code == 200:
result = alliance_list(http_response.text)
for alliance in result.alliances:
print(alliance)
# OR
# Note that result.alliances is a python generator, so once it's iteration is
# complete, it is empty, so for this to work after the previous example, you
# may need to do something like this to create a list (if you need one):
result = alliance_list(http_response.text)
print(list(result.alliances))
Timezones
import eveapi2
from eveapi2 import alliance_list
import requests
eveapi2.TIMEZONE = 'Europe/London' # default is UTC
http_response = requests.get(alliance_list.url)
if http_response.status_code == 200:
result = alliance_list(http_response.text)
result.current_time # Timezone aware.
result.cached_until # Timezone aware.
result.is_refreshable # Timezone aware.
Pass to Django/SQLAlchemy
from eveapi2 import alliance_list
result = alliance_list(requests.get(alliance_list.url))
for alliance in result.alliances:
a = AllianceModel(**dict(alliance))
a.save()
Note that some results (alliance obj for example) contain attributes in them that are actually generators containing other data (member corporations) that need to be handled before passing to your Model.
Examples
You can run examples after installing all the dependencies. The individual examples serve as documentation.
python example.py
Errors
When there is error in the XML data () this API will raise an APIError exception with information about the error. The message is passed into the exception text, and error code can be accessed under APIError.code.
from eveapi2 import APIError, character_id
xml_data = """
<eveapi version="2">
<currentTime>2015-03-14 08:57:48</currentTime>
<error code="122">Invalid or missing list of names.</error>
<cachedUntil>2015-03-14 20:57:48</cachedUntil>
</eveapi>
"""
try:
result = character_id(xml_data)
except APIError as e:
print('Error code: {}'.format(e.code))
print(e)
This code will print the following:
Error code: 122
Invalid or missing list of names.
Why do I need to get the xml data?
Simple, I can't dictate what library you should use for basic http request, and I provide you with the url you need to query. Also you might want to cache it in memcache/redis/DB or do all kinds of stuff with the response (load-balancing for example).
Note: you need to append HTTP GET attributes to the url (vCode, keyID, charID, etc).
Will there be Pyton2 support?
Maybe, it depends on the popularity, and if enough people will want it, it can happen.
Why are you not generating classes automagically?
As you can see, if the classes generation is not auto-magic, the code is super simple. And simple code is much better. Also creating classes dynamically is rather expensive and could slow things down. Since I can't know what the library will be used for, I only can make sure it is as fast as possible.
Why are you returning the data as generator instead of list?
Since the XML itself can be rather large (alliance list for example), we don't want to hold more data in memory on top of that.
Which API's are finished?
Section | Endpoint | Finished |
---|---|---|
Account | Account Status | Yes |
Account | Api Key Status | Yes |
Account | Character list | Yes |
API | Call List | Yes |
Character | Account Balance | No |
Character | Asset List | No |
Character | Calendar Event Attendees | No |
Character | Character Sheet | No |
Character | Contact List | No |
Character | Contact Notifications | No |
Character | Contracts | No |
Character | ContractItems | No |
Character | ContractBids | No |
Character | Factional Warfare Stats | No |
Character | Industry Jobs | No |
Character | Kill Log (Kill Mails) | No |
Character | Locations | No |
Character | Mail Bodies | No |
Character | Mailing Lists | No |
Character | Mail Messages (Headers) | No |
Character | Market Orders | No |
Character | Medals | No |
Character | Notifications | No |
Character | NotificationTexts | No |
Character | Research | No |
Character | Skill in Training | No |
Character | Skill Queue | No |
Character | Standings (NPC) | No |
Character | Upcoming Calendar Events | No |
Character | Wallet Journal | No |
Character | Wallet Transactions | No |
Corporation | Account Balances | No |
Corporation | Asset List | No |
Corporation | Contact List | No |
Corporation | Container Log | No |
Corporation | Contracts | No |
Corporation | ContractItems | No |
Corporation | ContractBids | No |
Corporation | Corporation Sheet | No |
Corporation | Factional Warfare Stats | No |
Corporation | Industry Jobs | No |
Corporation | Kill Log (Kill Mails) | No |
Corporation | Locations | No |
Corporation | Market Orders | No |
Corporation | Medals | No |
Corporation | Member Medals | No |
Corporation | Member Security | No |
Corporation | Member Security Log | No |
Corporation | Member Tracking | No |
Corporation | Outpost List | No |
Corporation | Outpost Service Detail | No |
Corporation | Shareholders | No |
Corporation | Standings (NPC) | No |
Corporation | StarbaseDetail Details (POS) | No |
Corporation | Starbase List (POS) | No |
Corporation | Titles | No |
Corporation | Wallet Journal | No |
Corporation | Wallet Transactions | No |
Eve | Alliance List | Yes |
Eve | Certificate Tree | XML Result Empty |
Eve | Character Affiliation | Yes |
Eve | Character ID (Name to ID Conversion) | Yes |
Eve | Character Info | No |
Eve | Character Name (ID to Name Conversion) | No |
Eve | Conquerable Station List (Includes Outposts) | No |
Eve | Error List | No |
Eve | Factional Warfare Stats | No |
Eve | Factional Warfare Top 100 Stats | No |
Eve | RefTypes List | No |
Eve | Skill Tree | No |
Eve | Type Name | No |
Map | Factional Warfare Systems (Occupancy Map) | No |
Map | Jumps | No |
Map | Kills | No |
Map | Sovereignty | No |
Map | Sovereignty Status (API disabled) | No |
Misc | Image (ID to Character Portrait and Corporation/Alliance Logo) | No |
Misc | Old Portraits | No |
Server | Server Status | Yes |
Contribute
If you like this API, you can help by submitting pull request with another part of the EVE API added.
Run tests
eveapi2
has py.test in its dependencies. To run tests use this command (from the root of the project):
py.test eveapi2/tests/*