Package: anonympy
anonympy 🕶️With ❤️ by ArtLabsOverviewGeneral Data Anonymization library for images, PDFs and tabular data. SeeArtLabs/projectsfor more or similar projects.Main FeaturesEase of use - this package was written to be as intuitive as possible.TabularEfficient - based on pd.DataFrameNumerous anonymization methodsNumeric dataGeneralization - BinningPerturbationPCA MaskingGeneralization - RoundingCategorical dataSynthetic DataResamplingTokenizationPartial Email MaskingDatetime dataSynthetic DatePerturbationImagesAnonymization techniquesPersonal Images (faces)BlurringPixaled Face BlurringSalt and Pepper NoiseGeneral ImagesBlurringPDFFind sensitive information and cover it with black boxesText, SoundIn DevelopmentInstallationDependenciesPython (>= 3.7)cape-privacyfakerpandasOpenCVpytesseracttransformers.         .  .  .  .Install with pipEasiest way to install anonympy is usingpippip install anonympyDue to conflicting pandas/numpy versions withcape-privacy, it's recommend to install them seperatelypip install cape-privacy==0.3.0 --no-depsInstall from sourceInstalling the library from source code is also possiblegit clone https://github.com/ArtLabss/open-data-anonimizer.git
cd open-data-anonimizer
pip install -r requirements.txt
make bootstrap
pip install cape-privacy==0.3.0 --no-depsDownloading RepositoryOr you could download this repository frompypiand run the following:cd open-data-anonimizer
python setup.py installUsage ExampleMore exampleshereTabular>>>fromanonympy.pandasimportdfAnonymizer>>>fromanonympy.pandas.utils_pandasimportload_dataset>>>df=load_dataset()>>>print(df)nameagebirthdatesalarywebemailssn0Bruce331915-04-1759234.32http://www.alandrosenburgcpapc.co.ukjosefrazier@owen.com3435543341Tony481970-05-2949324.53http://www.capgeminiamerica.co.ukeryan@lewis.com656564664# Calling the generic function>>>anonym=dfAnonymizer(df)>>>anonym.anonymize(inplace=False)# changes will be returned, not appliednameagebirthdateagewebemailssn0Stephanie Patel301915-05-1060000.05968b7880fpjordan@example.com391-77-92101Daniel Matthews501971-01-2150000.02ae31d40d4tparks@example.org872-80-9114# Or applying a specific anonymization technique to a column>>>fromanonympy.pandas.utils_pandasimportavailable_methods>>>anonym.categorical_columns...['name','web','email','ssn']>>>available_methods('categorical')...categorical_fakecategorical_fake_autocategorical_resamplingcategorical_tokenizationcategorical_email_masking>>>anonym.anonymize({'name':'categorical_fake',# {'column_name': 'method_name'}'age':'numeric_noise','birthdate':'datetime_noise','salary':'numeric_rounding','web':'categorical_tokenization','email':'categorical_email_masking','ssn':'column_suppression'})>>>print(anonym.to_df())nameagebirthdatesalarywebemail0Paul Lang311915-04-1760000.08ee92fb1bdj*****r@owen.com1Michael Gillespie421970-05-2950000.051b615c92ee*****n@lewis.comImages# Passing an Image>>>importcv2>>>fromanonympy.imagesimportimAnonymizer>>>img=cv2.imread('salty.jpg')>>>anonym=imAnonymizer(img)>>>blurred=anonym.face_blur((31,31),shape='r',box='r')# blurring shape and bounding box ('r' / 'c')>>>pixel=anonym.face_pixel(blocks=20,box=None)>>>sap=anonym.face_SaP(shape='c',box=None)blurredpixelsap# Passing a Folder>>>path='C:/Users/shakhansho.sabzaliev/Downloads/Data'# images are inside `Data` folder>>>dst='D:/'# destination folder>>>anonym=imAnonymizer(path,dst)>>>anonym.blur(method='median',kernel=11)This will create a folderOutputindstdirectory.# The Data folder had the following structure|1.jpg|2.jpg|3.jpeg|\---test|4.png|5.jpeg|\---test26.png# The Output folder will have the same structure and file names but blurred imagesPDFIn order to initializepdfAnonymizerobject we have to installpytesseractandpoppler, and provide path to the binaries of both as arguments or add paths to system variables>>>fromanonympy.pdfimportpdfAnonymizer# need to specify paths, since I don't have them in system variables>>>anonym=pdfAnonymizer(path_to_pdf="Downloads\\test.pdf",pytesseract_path=r"C:\Program Files\Tesseract-OCR\tesseract.exe",poppler_path=r"C:\Users\shakhansho\Downloads\Release-22.01.0-0\poppler-22.01.0\Library\bin")# Calling the generic function>>>anonym.anonymize(output_path='output.pdf',remove_metadata=True,fill='black',outline='black')test.pdfoutput.pdfIn case you only want to hide specific information, instead ofanonymizeuse other methods>>>anonym=pdfAnonymizer(path_to_pdf=r"Downloads\test.pdf")>>>anonym.pdf2images()#  images are stored in anonym.images variable>>>anonym.images2text(anonym.images)# texts are stored in anonym.texts#  Entities of interest>>>locs:dict=anonym.find_LOC(anonym.texts[0])# index refers to page number>>>emails:dict=anonym.find_emails(anonym.texts[0])# {page_number: [coords]}>>>coords:list=locs['page_1']+emails['page_1']>>>anonym.cover_box(anonym.images[0],coords)>>>display(anonym.images[0])DevelopmentContributionsTheContributing Guidehas detailed information about contributing code and documentation.Important LinksOfficial source code repo:https://github.com/ArtLabss/open-data-anonimizerDownload releases:https://pypi.org/project/anonympy/Issue tracker:https://github.com/ArtLabss/open-data-anonimizer/issuesLicenseBSD-3Code of ConductPlease seeCode of Conduct. 
All community members are expected to follow it.