Package: elite-dangerous-classes-library
Elite Dangerous Classes Library akaedclassesThis README is a work in progress.What is this library for?Data about systems, factions and stations in Elite Dangerous at your fingertips!Elite Dangerous Classes Library provides classes representing various objects in the game "Elite Dangerous" (systems, factions etc.).Developers can use these classes to speed up developing simple applications working with the game data.How to install it?pip install elite-dangerous-classes-libraryHow to use it?Here is an example of how it can be used. Note, that system name is all that needs to be provided. The rest is loaded
from the third party API.>>>fromedclassesimportSystem>>>sol=System.create(name="Sol")>>>forfaction_branchinsol.faction_branches:...print(f"{faction_branch}has{len(faction_branch.stations)}stations.")Faction'Sol Constitution Party'inSystem'Sol'has0stations.Faction'Federal Congress'inSystem'Sol'has1stations.Faction'Sol Nationalists'inSystem'Sol'has0stations.Faction'Sol Workers'Party' in System 'Sol' has 3 stations.Faction'Mother Gaia'inSystem'Sol'has6stations.Faction'Aegis Core'inSystem'Sol'has0stations.Generally, even though it's possible to initialize objects directly, it's advised to use thecreatemethod. Here is why:>>>fromedclassesimportSystem# trying to create the same object directly causes InstanceAlreadyExists error>>>system=System("Colonia")>>>system_2=System("Colonia")Error:edclasses.utils.InstanceAlreadyExists# using "create" method makes sure you get the same instance of System, so you don't have to worry about creating the# same object twice in two different places:>>>system=System.create(name="Colonia")>>>system_2=System.create(name="Colonia")>>>systemissystem_2TrueAnd here is an example of a function which is meant to find a station with mission for particular faction_branch:# missions.py:importrandomfromedclassesimportenumsdeffind_mission(faction_branch):stations=faction_branch.stationsrandom.shuffle(stations)forstationinstations:ifenums.StationService.MISSIONSinstation.services:return{"faction_branch":faction_branch,"station":station}returnNone>>>frommissionsimportfind_mission>>>fromedclassesimportFactionBranch,Faction,System>>>my_faction=Faction.create(name="Mother Gaia")>>>my_system=System.create(name="Sol")>>>my_faction_branch=FactionBranch.create(faction=my_faction,system=my_system)>>>mission_data=find_mission(my_faction_branch)>>>mission_station=mission_data["station"]>>>print(f"TRANSMISSION RECIEVED")>>>print(f"Commander, your presence is required at{mission_station}in the{mission_station.system}!")TRANSMISSIONRECIEVEDCommander,yourpresenceisrequiredatOcellus'Columbus'intheSystem'Sol'!Generally the library should let you focus on the logic of your application, instead of dealing with Elite Dangerous
data structure for 100th time.What classes are included?Currently the following objects are represented:System - single star systemFaction - faction entity, galaxy-wideFactionBranch - representation of a faction within a single system.OrbitalStation - station inside a system.The classes are not a full representation - such objects would be expensive to work with. However, they can be easily
extended if you need to add a particular attribute. They will definitely be extended gradually in the future, as new
needs show up.How are relations between objects kept?There is a special class representing parent-children relation (one-to-many). It takes care of updating both sides of
the relation. For example, when OrbitalStation instance changes its attributecontrolling_faction, the attributestationson the
FactionBranch instance is also updated, and vice versa. The parent is kept in sync with the children.Can I use the classes without external data source?From now on - Yes! The whole adapter engine has been extracted, so now, apart from full auto-refreshed classes available
in theclassesmodule, you can use the "offline" Model classes available in themodelsmodule.Model classesThey represent objects (factions, systems, faciton branches and stations) and keep the relation between them, but they
are static objects, not connected to any external data source. If you use these classes, they will only store the data
you have filled them with. For example. creating a SystemModel of system Sol will no longer let you fetch data about
"Sol" system:fromedclasses.modelsimportSystemModelsol_model=SystemModel.create(name="Sol")# the model has the same attributes ed class has, however it will not look for data anywhere else:print(sol_model.stations)[]# A normal instance of System class would at this point query API Adapter for data, but the model doesn't do that.AdvantagesIs there anything special about the model class itself if it doesn't fetch the data? Well, yes - relations. The model
classes are meant to work like a database - keep links between different objects in your program. Look at this example:>>>fromedclasses.modelsimportSystemModel,FactionModel,FactionBranchModel>>>sol=SystemModel.create(name="Sol")>>>sol.faction_branches[]>>>faction=FactionModel.create(name="Some Faction")>>>faction.faction_branches[]>>>faction_branch=FactionBranchModel.create(faction=faction,system=sol)# at these point the relations between are updated:>>>sol.faction_branches[SomeFactioninSol]>>>faction.faction_branches[SomeFactioninSol]How can this be useful? Even thoughedlasseshave been designed to be used with the API, maybe you have some idea
to create a whole universe simulation based on a CSV file on some Database of your own? This objects should make it
possible to do so without writing your own classes.Where is the data coming from?The library comes with a simple adapter to a magnificent API atwww.elitebgs.app(seriously, they made a great job, you
should check it out if you haven't already).
Every response is cached to avoid spamming the API with too many requests.
Apart from that, the API client is limited to 20 requests per minute. In the current representation breaking this limit
will raise RateLimitException. This behaviour might change in the future.When is the data loaded?The attributes are lazy, which means they get filled with data as you access them. For example:sol=System.create(name="Sol")# no data is being sent at this pointprint(sol.stations)# request for the data about stations is being made.print(sol.stations)# data is already there, no request is being madeAny words of advice?The library stores the whole data in the memory - which means, it might be expensive. I've designed it to work
with small scripts which I plan to use along VoiceAttack, to enrich my experience while playing. It's not meant for
massive data analysis, to be used on web servers etc. - it's designed to work with a few systems of interest, or a few
factions of interests. If your app is too data-hungry, it will result in the following problems:you will send too many requests to the API, causing rate limit error (or even a ban - respect the APIs!)your application will work slowly - the more data the app has to keep track of, the slower it runsyou might run out of memory.Can I use different data sources? Can I add more fields?Yes, the provided EliteBgsApiAdapter is just an example. You can write a similar adapter, or extend this one, and then
connect it to the proper class in edclasses. I will add a more detailed tutorial in the future.You can also use the model classes (check out ## model classes above) and create your own data source system.Why don't you XYZ:The project is in very early phase. Have any idea? Please open an issue, I would be glad to discuss.