Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Check if a file is ignored by a .zgitignore file, compatible with .gitignore syntax

Project description

zgitignore is a small library to check if a file has been excluded by a .zgitignore file (those are compatible with .gitignore files).


As simple as it can be via pip:

$ pip install zgitignore

Or direct installation from source:

$ git clone git://
$ cd zgitignore
$ python install


import zgitignore

#ZgitIgnore class stores the patterns, optionally takes ignore_case parameter
#by default, it is case sensitive to match .gitignore behaviour
f = zgitignore.ZgitIgnore(['build/', 'dist/', '*egg-info'])

#Patterns ending with / will match folders only:
print('build file ignored?: ', f.is_ignored('build')) #False

#When matching directories, set second parameter to True:
print('build folder ignored?: ', f.is_ignored('build', True)) #True

#It is case sensitive by default:
print('BUILD folder ignored?: ', f.is_ignored('BUILD', True)) #False

#Want it to be case-insensitive? No problem
f = zgitignore.ZgitIgnore(['*pycache*', '*pyc'], True) #second parameter is ignore_case

print('PYCACHE file ignored?', f.is_ignored('PYCACHE')) #True

#You can also add patterns later
ignorefile = zgitignore.ZgitIgnore(ignore_case=True)

    with open('.gitignore', 'r') as f:

#You can start path with ./ or not.
#Paths are normalized to match Unix style paths
print('./a/b/c/d/e ignored?', ignorefile.is_ignored('./a/b/c/d/e'))


zgitignore supports format similar to .gitignore file format. Differences are:

  • ** works everywhere


    Will match aaapotato2000/beeeee/llllll/sdsdooo

  • It can embed custom regex via {}. You can use \} to pass } to regex and \\ to pass \ to regex


    Will match aaa1256oobbii888


    Will match aaa#00ffff888

Project details

Release history Release notifications

This version
History Node


History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
zgitignore-0.8.0.tar.gz (5.7 kB) Copy SHA256 hash SHA256 Source None Sep 6, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page