Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python Script to parse permissions from an AndroidManifest.xml file, and sort them alphabetically.
from xml.dom.minidom import parseString
# Documentation on Permissions in AndroidManifest.xml
data = '' # string data from file
with open('AndroidManifest.xml', 'r') as f:
data =
dom = parseString(data) # parse file contents to xml dom
nodes = dom.getElementsByTagName('uses-permission') # xml nodes named "uses-permission"
nodes+= dom.getElementsByTagName('uses-permission-sdk-23') # xml nodes named "uses-permission-sdk-23"
permissions = [] # holder for all permissions as we gather them
# Iterate over all the uses-permission nodes
for node in nodes:
permissions += [node.getAttribute("android:name")] # save permissionName to our list
# Print sorted list
for permission in sorted(permissions): # sort permissions and iterate
print(permission) # print permission name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment