eth-bloom


Nameeth-bloom JSON
Version 3.0.1 PyPI version JSON
download
home_pagehttps://github.com/ethereum/eth-bloom
SummaryA python implementation of the bloom filter used by Ethereum
upload_time2024-04-24 16:01:35
maintainerNone
docs_urlNone
authorThe Ethereum Foundation
requires_python<4,>=3.8
licenseMIT
keywords ethereum blockchain evm trie merkle
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # eth-bloom

[![Join the conversation on Discord](https://img.shields.io/discord/809793915578089484?color=blue&label=chat&logo=discord&logoColor=white)](https://discord.gg/GHryRvPB84)
[![Build Status](https://circleci.com/gh/ethereum/eth-bloom.svg?style=shield)](https://circleci.com/gh/ethereum/eth-bloom)
[![PyPI version](https://badge.fury.io/py/eth-bloom.svg)](https://badge.fury.io/py/eth-bloom)
[![Python versions](https://img.shields.io/pypi/pyversions/eth-bloom.svg)](https://pypi.python.org/pypi/eth-bloom)

A python implementation of the bloom filter used by Ethereum.

> This library and repository was previously located at https://github.com/pipermerriam/ethereum-bloom.  It was transferred to the Ethereum foundation github in November 2017 and renamed to `eth-bloom`.  The PyPi package was also renamed from `ethereum-bloom` to \`eth-bloom.

Read more in the documentation below. [View the change log](https://github.com/ethereum/eth-bloom/blob/main/CHANGELOG.rst).

For more information on what Ethereum Bloom Filters are see [here](what_is_eth-bloom.txt).

## Quickstart

```sh
python -m pip install eth-bloom
```

## Usage

The `BloomFilter` object

```python
>>> from eth_bloom import BloomFilter
>>> b = BloomFilter()
>>> b'a value' in b  # check whether a value is present
False
>>> b.add(b'a value')  # add a single value
>>> b'a value' in b
True
>>> int(b)  # cast to an integer
3458628712844765018311492773359360516229024449585949240367644166080576879632652362184119765613545163153674691520749911733485693171622325900647078772681584616740134230153806267998022370194756399579977294154062696916779055028045657302214591620589415314367270329881298073237757853875497241510733954508399863880080986777555986663988492288946856978031023631618215522505971170427986911575695114157059398791122395379400594948096
>>> bin(b)  # cast to a binary string
'0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
```

You can also add an iterable of items to a bloom filter.

```python
>>> b = BloomFilter()
>>> b'value-a' in b
False
>>> b'value-b' in b
False
>>> b.extend([b'value-a', b'value-b'])
>>> b'value-a' in b
True
>>> b'value-b' in b
True
```

You can initialize a bloom filter from an iterable of byte strings.

```python
>>> b = BloomFilter.from_iterable([b'value-a', b'value-b'])  # initialize from an iterable of values.
>>> b'value-a' in b
True
>>> b'value-b' in b
True
```

You can initialize a bloom filter from the integer representation of the bloom bits.

```python
>>> b = BloomFilter(3458628712844765018311492773359360516229024449585949240367644166080576879632652362184119765613545163153674691520749911733485693171622325900647078772681584616740134230153806267998022370194756399579977294154062696916779055028045657302214591620589415314367270329881298073237757853875497241510733954508399863880080986777555986663988492288946856978031023631618215522505971170427986911575695114157059398791122395379400594948096)
>>> b'a value' in b
True
```

You can also merge bloom filters

```python
>>> from eth_bloom import BloomFilter
>>> b1 = BloomFilter()
>>> b2 = BloomFilter()
>>> b1.add(b'a')
>>> b1.add(b'common')
>>> b2.add(b'b')
>>> b2.add(b'common')
>>> b'a' in b1
True
>>> b'b' in b1
False
>>> b'common' in b1
True
>>> b'a' in b2
False
>>> b'b' in b2
True
>>> b'common' in b2
True
>>> b3 = b1 + b2  # using addition
>>> b'a' in b3
True
>>> b'b' in b3
True
>>> b'common' in b3
True
>>> b4 = b1 | b2  # or using bitwise or
>>> b'a' in b4
True
>>> b'b' in b4
True
>>> b'common' in b4
True
>>> b1 |= b2  # or using in-place operations (works with += too)
>>> b'a' in b1
True
>>> b'b' in b1
True
>>> b'common' in b1
True
```

## Developer Setup

If you would like to hack on eth-bloom, please check out the [Snake Charmers
Tactical Manual](https://github.com/ethereum/snake-charmers-tactical-manual)
for information on how we do:

- Testing
- Pull Requests
- Documentation

We use [pre-commit](https://pre-commit.com/) to maintain consistent code style. Once
installed, it will run automatically with every commit. You can also run it manually
with `make lint`. If you need to make a commit that skips the `pre-commit` checks, you
can do so with `git commit --no-verify`.

### Development Environment Setup

You can set up your dev environment with:

```sh
git clone git@github.com:ethereum/eth-bloom.git
cd eth-bloom
virtualenv -p python3 venv
. venv/bin/activate
python -m pip install -e ".[dev]"
pre-commit install
```

### Release setup

To release a new version:

```sh
make release bump=$$VERSION_PART_TO_BUMP$$
```

#### How to bumpversion

The version format for this repo is `{major}.{minor}.{patch}` for stable, and
`{major}.{minor}.{patch}-{stage}.{devnum}` for unstable (`stage` can be alpha or beta).

To issue the next version in line, specify which part to bump,
like `make release bump=minor` or `make release bump=devnum`. This is typically done from the
main branch, except when releasing a beta (in which case the beta is released from main,
and the previous stable branch is released from said branch).

If you are in a beta version, `make release bump=stage` will switch to a stable.

To issue an unstable version when the current version is stable, specify the
new version explicitly, like `make release bump="--new-version 4.0.0-alpha.1 devnum"`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ethereum/eth-bloom",
    "name": "eth-bloom",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.8",
    "maintainer_email": null,
    "keywords": "ethereum blockchain evm trie merkle",
    "author": "The Ethereum Foundation",
    "author_email": "snakecharmers@ethereum.org",
    "download_url": "https://files.pythonhosted.org/packages/f6/33/f8c9233d7c5e94b64e3885c037d3a7f6ab199fa55ede580cf8d9b66cd724/eth_bloom-3.0.1.tar.gz",
    "platform": null,
    "description": "# eth-bloom\n\n[![Join the conversation on Discord](https://img.shields.io/discord/809793915578089484?color=blue&label=chat&logo=discord&logoColor=white)](https://discord.gg/GHryRvPB84)\n[![Build Status](https://circleci.com/gh/ethereum/eth-bloom.svg?style=shield)](https://circleci.com/gh/ethereum/eth-bloom)\n[![PyPI version](https://badge.fury.io/py/eth-bloom.svg)](https://badge.fury.io/py/eth-bloom)\n[![Python versions](https://img.shields.io/pypi/pyversions/eth-bloom.svg)](https://pypi.python.org/pypi/eth-bloom)\n\nA python implementation of the bloom filter used by Ethereum.\n\n> This library and repository was previously located at https://github.com/pipermerriam/ethereum-bloom.  It was transferred to the Ethereum foundation github in November 2017 and renamed to `eth-bloom`.  The PyPi package was also renamed from `ethereum-bloom` to \\`eth-bloom.\n\nRead more in the documentation below. [View the change log](https://github.com/ethereum/eth-bloom/blob/main/CHANGELOG.rst).\n\nFor more information on what Ethereum Bloom Filters are see [here](what_is_eth-bloom.txt).\n\n## Quickstart\n\n```sh\npython -m pip install eth-bloom\n```\n\n## Usage\n\nThe `BloomFilter` object\n\n```python\n>>> from eth_bloom import BloomFilter\n>>> b = BloomFilter()\n>>> b'a value' in b  # check whether a value is present\nFalse\n>>> b.add(b'a value')  # add a single value\n>>> b'a value' in b\nTrue\n>>> int(b)  # cast to an integer\n3458628712844765018311492773359360516229024449585949240367644166080576879632652362184119765613545163153674691520749911733485693171622325900647078772681584616740134230153806267998022370194756399579977294154062696916779055028045657302214591620589415314367270329881298073237757853875497241510733954508399863880080986777555986663988492288946856978031023631618215522505971170427986911575695114157059398791122395379400594948096\n>>> bin(b)  # cast to a binary string\n'0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'\n```\n\nYou can also add an iterable of items to a bloom filter.\n\n```python\n>>> b = BloomFilter()\n>>> b'value-a' in b\nFalse\n>>> b'value-b' in b\nFalse\n>>> b.extend([b'value-a', b'value-b'])\n>>> b'value-a' in b\nTrue\n>>> b'value-b' in b\nTrue\n```\n\nYou can initialize a bloom filter from an iterable of byte strings.\n\n```python\n>>> b = BloomFilter.from_iterable([b'value-a', b'value-b'])  # initialize from an iterable of values.\n>>> b'value-a' in b\nTrue\n>>> b'value-b' in b\nTrue\n```\n\nYou can initialize a bloom filter from the integer representation of the bloom bits.\n\n```python\n>>> b = BloomFilter(3458628712844765018311492773359360516229024449585949240367644166080576879632652362184119765613545163153674691520749911733485693171622325900647078772681584616740134230153806267998022370194756399579977294154062696916779055028045657302214591620589415314367270329881298073237757853875497241510733954508399863880080986777555986663988492288946856978031023631618215522505971170427986911575695114157059398791122395379400594948096)\n>>> b'a value' in b\nTrue\n```\n\nYou can also merge bloom filters\n\n```python\n>>> from eth_bloom import BloomFilter\n>>> b1 = BloomFilter()\n>>> b2 = BloomFilter()\n>>> b1.add(b'a')\n>>> b1.add(b'common')\n>>> b2.add(b'b')\n>>> b2.add(b'common')\n>>> b'a' in b1\nTrue\n>>> b'b' in b1\nFalse\n>>> b'common' in b1\nTrue\n>>> b'a' in b2\nFalse\n>>> b'b' in b2\nTrue\n>>> b'common' in b2\nTrue\n>>> b3 = b1 + b2  # using addition\n>>> b'a' in b3\nTrue\n>>> b'b' in b3\nTrue\n>>> b'common' in b3\nTrue\n>>> b4 = b1 | b2  # or using bitwise or\n>>> b'a' in b4\nTrue\n>>> b'b' in b4\nTrue\n>>> b'common' in b4\nTrue\n>>> b1 |= b2  # or using in-place operations (works with += too)\n>>> b'a' in b1\nTrue\n>>> b'b' in b1\nTrue\n>>> b'common' in b1\nTrue\n```\n\n## Developer Setup\n\nIf you would like to hack on eth-bloom, please check out the [Snake Charmers\nTactical Manual](https://github.com/ethereum/snake-charmers-tactical-manual)\nfor information on how we do:\n\n- Testing\n- Pull Requests\n- Documentation\n\nWe use [pre-commit](https://pre-commit.com/) to maintain consistent code style. Once\ninstalled, it will run automatically with every commit. You can also run it manually\nwith `make lint`. If you need to make a commit that skips the `pre-commit` checks, you\ncan do so with `git commit --no-verify`.\n\n### Development Environment Setup\n\nYou can set up your dev environment with:\n\n```sh\ngit clone git@github.com:ethereum/eth-bloom.git\ncd eth-bloom\nvirtualenv -p python3 venv\n. venv/bin/activate\npython -m pip install -e \".[dev]\"\npre-commit install\n```\n\n### Release setup\n\nTo release a new version:\n\n```sh\nmake release bump=$$VERSION_PART_TO_BUMP$$\n```\n\n#### How to bumpversion\n\nThe version format for this repo is `{major}.{minor}.{patch}` for stable, and\n`{major}.{minor}.{patch}-{stage}.{devnum}` for unstable (`stage` can be alpha or beta).\n\nTo issue the next version in line, specify which part to bump,\nlike `make release bump=minor` or `make release bump=devnum`. This is typically done from the\nmain branch, except when releasing a beta (in which case the beta is released from main,\nand the previous stable branch is released from said branch).\n\nIf you are in a beta version, `make release bump=stage` will switch to a stable.\n\nTo issue an unstable version when the current version is stable, specify the\nnew version explicitly, like `make release bump=\"--new-version 4.0.0-alpha.1 devnum\"`\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A python implementation of the bloom filter used by Ethereum",
    "version": "3.0.1",
    "project_urls": {
        "Homepage": "https://github.com/ethereum/eth-bloom"
    },
    "split_keywords": [
        "ethereum",
        "blockchain",
        "evm",
        "trie",
        "merkle"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b56bc06b2c72035d24ae5ebc06b56b37a3e3da3e9a80bdfe7b78d3987f9c5013",
                "md5": "a6f3ecf3a54ff25ad155eb13faa86526",
                "sha256": "c1eb51cb9f9ec8834b691d67e73c02c4e79e22c81ae8058209971803236ffbb2"
            },
            "downloads": -1,
            "filename": "eth_bloom-3.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a6f3ecf3a54ff25ad155eb13faa86526",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.8",
            "size": 5703,
            "upload_time": "2024-04-24T16:01:34",
            "upload_time_iso_8601": "2024-04-24T16:01:34.535157Z",
            "url": "https://files.pythonhosted.org/packages/b5/6b/c06b2c72035d24ae5ebc06b56b37a3e3da3e9a80bdfe7b78d3987f9c5013/eth_bloom-3.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f633f8c9233d7c5e94b64e3885c037d3a7f6ab199fa55ede580cf8d9b66cd724",
                "md5": "c32b7fe4e608f30f3625df0997c57b85",
                "sha256": "6be3dfa44a597a0bc8d974c381fb9a60bbcadfb56e88e69ab55ba538d90b3256"
            },
            "downloads": -1,
            "filename": "eth_bloom-3.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c32b7fe4e608f30f3625df0997c57b85",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.8",
            "size": 8516,
            "upload_time": "2024-04-24T16:01:35",
            "upload_time_iso_8601": "2024-04-24T16:01:35.814436Z",
            "url": "https://files.pythonhosted.org/packages/f6/33/f8c9233d7c5e94b64e3885c037d3a7f6ab199fa55ede580cf8d9b66cd724/eth_bloom-3.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-24 16:01:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ethereum",
    "github_project": "eth-bloom",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "tox": true,
    "lcname": "eth-bloom"
}
        
Elapsed time: 2.66554s