onix.contexts module

Object, factories and utilities for bundling and accessing resources

class onix.contexts.Context(**resources)[source]

Bases: object

Grouping of resources and static lookups, bundled together for ease of access.

Notes

Be careful when using this in a multiprocessor context, as transmitting all the lookups to each worker process is a metric ton of overhead when it’s extremely unlikely that each worker needs every single resource.

Parameters:**resources – the resources to be bundled. Note that there’s no need to limit one’s self to the attributes listed below.
aliases

dict

the data encoded in aliases.js on PS. The keys are the alternate names, the values are the correct names.

formats

dict

the data encoded in formats.js on PS, post-processed for increased utility. The keys are the sanitized format names. The values are the various configurations and metadata for the metagame.

formats_data

dict

the data encoded in formats-data.js on PS. The keys are the species / forme names, the values contain information like current tier and random battle move pool

items

dict

the data encoded in items.js on PS. The keys are sanitized item names, the values associated metadata including, for mega stones, which Pokemon it mega-evolves.

moves

dict

the data encoded in moves.js on PS. The keys are sanitized move names, the values the associated metadata including move type and base power

pokedex

dict

the data encoded in pokedex.js on PS. The keys are the species / forme names. The values contain information like base stats and valid abilities.

accessible_formes

dict

a mapping of species and formes to the routes they have to access other formes.

natures

dict

The keys are the sanitized nature names, the values the associated metadata, such as which stat gets boosted and which gets lowered.

species_lookup

dict

mapping of sanitized species names or forme-concatenations (e.g. “sceptile,sceptilemega”) to their display names. This is what handles things like determing whether megas are tiered together or separately or what counts as an “appearance-only” forme.

sanitizer

onix.utilities.Sanitizer

the sanitizer to use to normalize data and model objedts.

exception onix.contexts.ResourceMissingError(resource)[source]

Bases: exceptions.Exception

Raised if an expected resource is not present in a given context

Parameters:resource (str) – the name of the missing resource
onix.contexts.require(context, *resources)[source]

Validate that the specified Context has all the specified resources

Parameters:
  • context (Context) – the context to validate
  • *resources – the names of the attributes to require
Raises:

ResourceMissingError – if a required resource is missing from the context

onix.contexts.get_standard_context(force_refresh=False)[source]

Create a Context with all the standard (current generation, non-mod) resources.

Parameters:force_refresh (bool, optional) – By default, this method will try to load the resources from the local file cache. Set to False to force it to freshly download scrape the Pokemon Showdown data.
Returns:A context with all the standard resources
Return type:Context
onix.contexts.get_historical_context(timestamp)[source]

Create a Context with all the resources as they were at a given date and time. Useful for performing historical analyses or for working around mid-month changes

Parameters:timestamp (datetime.datetime) – The date and time (in UTC) desired
Returns:A context with all the resources as they were at the specified timestamp
Return type:Context