Package: powerchallonge
powerchallonge is a client libary for theChallonge.com API.All the API Methods are supported.ContentsPython version compatibilityDependenciesInstallationBasic usageKnown IssuesRunning the testsAdvanced usagePassing parametersAdvanced user settingsConvert xml and json files to paramsAPI Methods examples listTournamentsParticipantsMatchesMatch AttachmentsPython version compatibility2.73.3+DependenciesrequestsInstallationpip install powerchallongeBasic usageimportchallonge#Configure your settingsapi_key='YOURCHALLONGEAPIKEY'challonge.set_user_settings(api_key)#Retrieve a set of tournaments created with your account as a Python list of dictionariestournaments=challonge.tournaments.index()fortournamentintournaments:print(tournament['name'],tournament['id'])#Retrieve a single tournamentas a Python dictionnary using it's id or challonge like urltournament=challonge.tournaments.show(1234)print(tournament['name'],tournament['game_name'])Known IssuesAfter a participant is checked in using participants.check_in(), the ‘checked_in’ field remains False but the participant is properly checked in on the siteThis problem doesn’t appear for the participants.undo_check_in(), the field is properly set from True to False when using itChallonge API returns error 500 when Creatin/Updating a match_attachment assetWhen using match_attachments.update(), the updated field does not seem to get changed when doing a verification with match_attachments.show(), however the update is effective and shows up correctly on the siteAll these issues have been reported to challonge.Running the testsThe tests/tests.py script verifies functionality for all the API Methods (except the ones with known issues) and powerchallonge specific functions such as settings configuring and both json and xml conversion functions.How to run the tests:Set a CHALLONGE_API_KEY environment variableFrom the repository’s root directorypython -m unittest discover -s tests -p "tests.py" -vAdvanced usagePassing parametersSome methods only have positional arguments, some require the keyword argument ‘params’params should be a dictionnary of the parameters you intend to use in the method.myparams={'subdomain':my_subdomain}subdomain_tournaments=challonge.tournaments.index(params=myparams)myparams2={'name':'tournament1','url':'tournament123123129032901'}tournament1=challonge.tournaments.create(params=myparams2)Advanced user settingsBy default, you only need your api key and the set_user_settings() function to use powerchallonge.You can use set_user_settings_advanced() for more customizationThe variables below are the default settings if set_user_settings_advanced() isn’t called.api_key="YOURCHALLONGEAPIKEY"# Your Challonge API keyeasy_tournament_identifier=False# True to use full URLs for referring to tournaments# instead of challonge like URLs.# false to use regular challonge API like URLs.query_type=".json"# The desired response expected from the challonge API, '.json' or '.xml'raw_response=False# The desired response, False for python like objects : lists, dictionnaries.# True for raw response from the API in the form of a Requests Response Object# http://docs.python-requests.org/en/master/api/#requests.Response#Apply the settingschallonge.set_user_settings_advanced(api_key,easy_tournament_identifier,query_type,raw_response,verbose_level,test_mode)Convert xml and json files to paramspowerchallonge comes with tools to convert json or xml files to a dictionnary that can be used agument in the API methods.
This allows the user to create custom templates for specific tournaments and save them as .json or .xml and load them easily.the functions only supports single parent type json/xml files the childs will be the key:elements in the dictionnarymyparams=challonge.json_to_params(path_to_json_file)myparams=challonge.xml_to_params(path_to_xml_file)Elements are always processed as strings or booleans, if you want an element to be a list (only interesting in the case of participants.bulk_add() ) use the following in your xml file :<name type='list'>player1,player2,player3</name>API Methods examples listIf raw_response is set to False (default), the output for any API method used will be a Python object.If raw response is set to True, the output for any API method used will be a requests response object.TournamentsTournaments : Index.# params argument is optionalr=challonge.tournaments.index()print(r)# a list of dictionaries of attributes (one dictionary per tournament)Tournaments : Create.# params argument is optional but necessary (challonge error later on if missing)myparams={'name':'mytournament123123','url':'mytournament123123'}myparams['start_at']="2020/02/16T17:00:00+00:00"#If you don't set an offset ("+00:00" above), the hour will be inconsistent#Always set your start_time to UTC+your_zone_offsetr=challonge.tournaments.create(params=myparams)print(r)# a dictionary of the attributes of the tournamentTournaments : Show.# params argument is optionalr=challonge.tournaments.show(identifier)print(r)# a dictionary of the attributes of the tournamentTournaments : Update.# params argument is optional but necessary (challonge error later on if missing)myparams{'description':'new_description'}r=challonge.tournaments.update(identifier,params=myparams)print(r)# a dictionary of the attributes of tournamentTournaments : Destroy.# no params argument requiredr=challonge.tournaments.destroy(identifier)print(r)# a dictionary of the attributes of the tournamentTournaments : Process Check-ins.# params argument is optionalr=challonge.tournaments.process_check_ins(identifier)print(r)# a dictionary of the attributes of the tournamentTournaments : Abort Check-in.# params argument is optionalr=challonge.tournaments.abort_check_ins(identifier)print(r)# a dictionary of the attributes of the tournamentTournaments : Start.# params argument is optionalr=challonge.tournaments.start(identifier)print(r)# a dictionary of the attributes of the tournamentTournaments : Finalize.# params argument is optionalr=challonge.tournaments.finalize(identifier)print(r)# a dictionary of the attributes of the tournamentTournaments : Reset.Participants# params argument is optionalr=challonge.tournaments.reset(identifier)print(r)# a dictionary of the attributes of the tournamentParticipants : index.# params argument is optionalr=challonge.participants.index(identifier)print(r)# a list of dictionnaries of attributes (one dictionnary per participant)Participants : Create.# params argument is optional but necessary (challonge error later on if missing)myparams={'name':'player1'}r=challonge.participants.create(identifier,params=myparams)print(r)# a dictionary of the attributes of the participantParticipants : Bulk-Add.# params argument is optional but necessary (challonge error later on if missing)# For the bulk_add to work, the 'name' field of params must be a list of the namesmyparams={'name':['player1','player2','player3']}r=challonge.participants.bulk_add(identifier,params=myparams)print(r)# a list of dictionnaries of attributes (one dictionnary per added participant)Participants : Show.# params argument is optionalr=challonge.participants.show(identifier,participant_id)print(r)# a dictionary of the attributes of the participantParticipants : Update.# params argument is optional but necessary (challonge error later on if missing)myparams={'name':'player1_update'}r=challonge.participants.update(identifier,participant_id,params=myparams)print(r)# a dictionary of the attributes of the participantParticipants : Check-in.# no params argument requiredr=challonge.participants.check_in(identifier,participant_id)print(r)# a dictionary of the attributes of the participant#The participant is properly checked-in on the site#But the 'checked_in' field will still be set to False, check Known IssuesParticipants : Undo Check In.# no params argument requiredr=challonge.participants.undo_check_in(identifier,participant_id)print(r)# a dictionary of the attributes of the participantParticipants : Destroy.# no params argument requiredr=challonge.participants.destroy(identifier,participant_id)print(r)# a dictionary of the attributes of the participantParticipants : Randomize.# no params argument requiredr=challonge.participants.randomize(identifier)print(r)# a list of dictionnaries of attributes (one dictionary per participant)MatchesMatches : Index.# params argument is optionalr=challonge.matches.index(identifier)print(r)# a list of dictionaries of attributes (one dictionary per match)Matches : Show.# params argument is optionalr=challonge.matches.show(identifier,match_id)print(r)# a dictionary of the attributes of the matchMatches : Update.# params argument is optional but necessary (challonge error later on if missing)myparams={'scores_csv':'1-0'}r=challonge.matches.update(identifier,match_id,params=myparams)print(r)# a dictionary of the attributes of the matchMatches : Reopen.# no params argument requiredr=challonge.matches.reopen(identifier,match_id)print(r)# a dictionary of the attributes of the matchMatch Attachments : Index.# no params argument requiredr=challonge.match_attachments.index(identifier,match_id)print(r)# a list of dictionaries of attributes (one dictionary per match attachment)Match AttachmentsMatch Attachments : Create.#Doesn't work if asset is a file (Error 500, check known issues)# params argument is optional but necessary (challonge error later on if missing)myparams={'description':'description'}r=challonge.match_attachments.create(identifier,match_id,params=myparams)print(r)# a dictionary of the attributes of the match attachmentMatch Attachments : Show.# no params argument requiredr=challonge.match_attachments.show(identifier,match_id,attachment_id)print(r)# a dictionary of the attributes of the match attachmentMatch Attachments : Update.# params argument is optional but necessary (challonge error later on if missing)myparams={'description':'new_description'}r=challonge.match_attachments.update(identifier,match_id,attachment_id,params)print(r)# a dictionary of the attributes of the match attachment#the updated field does not seem to get changed when doing a verification#with match_attachments.show(),#however the update is effective and shows up correctly on the siteMatch Attachments : Destroy.# no params argument requiredr=challonge.match_attachments.destroy(identifier,match_id,attachment_id)print(r)# a dictionary of the attributes of the match attachment