binda


Namebinda JSON
Version 1.0.22 PyPI version JSON
download
home_page
SummaryRead and write binary data using Pandas
upload_time2023-10-02 13:31:30
maintainer
docs_urlNone
author
requires_python>=3.6
licenseMIT License Copyright (c) 2023 Jamie Cash Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords analytics binary data hex hexadecimal pandas
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # binda

Read and write binary data using Pandas.

Map the data in the binary file to variables, single data structures or 
repeating data structures. Once mapped, the binary file can be viewed and 
edited using Pandas DataFrames.

## Installation

binda can be installed using pip or conda.

```
pip install binda
```

or

```
conda install binda
```

## Docs

The documentation for binda is available on GitHub Docs here: 
https://jamiecash.github.io/binda/binda.html

## Usage

Given the following binary data (represented as hex):
```
42:4c:4f:43:4b:44:41:54:41:64:4a:61:6d:69:65:20
43:61:73:68:20:20:20:20:20:01:65:42:6f:62:62:79
20:53:6d:69:74:68:20:20:20:20:00:66:4d:72:20:42
65:61:6e:20:20:20:20:20:20:20:20:01:4d:72:20:41
75:74:68:6f:72:20:20:20:20:20:20:0a:00:ff:ec:00
00:f7:42
```

Which contaains:
* A 9 bytes string containing 'BLOCKDATA'
* 3 repeating records of 17 bytes containing a 1 byte integer ID, a 15 bytes 
string NAME and a 1 byte interger ACTIVE flag
* 19 bytes containing a 15 bytes string AUTHOR, a 2 bytes integer ID and a 
2 bytes bigendian signed integer POINTS.

First create the data handler with the data.

```python
data = b'BLOCKDATAdJamie Cash     \x01eBobby Smith    \x00fMr Bean        '\
      +b'\x01Mr Author      \n\x00\xff\xec\x00\x00\xf7B'

handler = bd.DataHandler(data)
```

The name from the first record can be read by creating a variable, specifying a
name for the variable, it's size, it's datatye and it's offset.

```python
print("Name: " + handler.read_variable(bd.Variable('name', 15, str, 10)))
```

```
Name: Jamie Cash
```

The 19 bytes of author data starting at offset 60 can be read into a Pandas 
DataFrame by specifying the layout of the structure, including its variables. 
The DataHandler can then be used to read it.

```python
author_struct = \
      bd.Structure(60, [bd.Variable('AUTHOR', 15, str), 
                        bd.Variable('ID', 2, int), 
                        bd.Variable('POINTS', 2, int, 
                                    byteorder=bd.ByteOrder.BIG, signed=True)])
handler.add_structure('author', author_struct)
df = handler.read_structure('author')
df
```
![image](https://github.com/jamiecash/binda/raw/main/example/img/single_structure.png)

The three row repeating structure can be read in a similar way, but this time
also specifying the number of rows.

```python
people_struct = \
  bd.Structure(9, [bd.Variable('ID', 1, int),
                    bd.Variable('NAME', 15, str),
                    bd.Variable('ACTIVE', 1, bool)], rows=3)

handler.add_structure('people', people_struct)
df = handler.read_structure('people')
df
```

![image](https://github.com/jamiecash/binda/raw/main/example/img/repeating_structure.png)

The dataframe can be edited, and saved back to edit the binary data.

```python
# Change Bobby Smiths name to Bobby Smythe, his ID to 200 and is active 
# status to True
df.loc[df['ID'] == 101, 'ID'] = 200
df.loc[df['ID'] == 200, 'NAME'] = 'Bobby Smythe   '
df.loc[df['ID'] == 200, 'ACTIVE'] = True
handler.write_structure('people', df)

# Confirm that the change has been made to the data by re-reading it and 
# displaying
df = handler.read_structure('people')
df
```

![image](https://github.com/jamiecash/binda/raw/main/example/img/repeating_structure_changed.png)

We can also check the binary data to see the change.
```python
print(handler.data[26:43])
```

```
b'\xc8Bobby Smythe   \x01'
```

## Examples

2 Jupyter notebooks are provided in the examples folder, one containing the code 
from the **Usage** section above and one containing an example on reading and 
writimg Exif data to a .jpeg file.

## Joining the Project Team

This project is maintained on [GitHub](https://github.com/jamiecash/binda):

If you would like to contribute to this project by fixing issues or adding 
features, please follow the below steps:
* If adding functionality or fixing an issue not already raised on GitHub, raise 
an issue.
* Assign the issue(s) to yourself.
* Fork the project.
* Create a branch from master.
* Make the required changes to the project in your local branch.
* Commit your changes, adding comments referencing the issues that your changes 
fix.
* Push this branch to your GitHub project.
* Open a Pull Request on GitHub.
* Email me at jlcash@gmail.com to discuss the changes made.
* Once changes have been agreed, I will merge or close the pull request.
* Sync the updated master back to your fork.
* Close the issues that were fixed.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "binda",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "analytics,binary,data,hex,hexadecimal,pandas",
    "author": "",
    "author_email": "Jamie Cash <jlcash@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/bd/64/d00fbe3d2e07e8d7bbd73e17acd8da834c98e9850b855c00b8aa7b4733e7/binda-1.0.22.tar.gz",
    "platform": null,
    "description": "# binda\n\nRead and write binary data using Pandas.\n\nMap the data in the binary file to variables, single data structures or \nrepeating data structures. Once mapped, the binary file can be viewed and \nedited using Pandas DataFrames.\n\n## Installation\n\nbinda can be installed using pip or conda.\n\n```\npip install binda\n```\n\nor\n\n```\nconda install binda\n```\n\n## Docs\n\nThe documentation for binda is available on GitHub Docs here: \nhttps://jamiecash.github.io/binda/binda.html\n\n## Usage\n\nGiven the following binary data (represented as hex):\n```\n42:4c:4f:43:4b:44:41:54:41:64:4a:61:6d:69:65:20\n43:61:73:68:20:20:20:20:20:01:65:42:6f:62:62:79\n20:53:6d:69:74:68:20:20:20:20:00:66:4d:72:20:42\n65:61:6e:20:20:20:20:20:20:20:20:01:4d:72:20:41\n75:74:68:6f:72:20:20:20:20:20:20:0a:00:ff:ec:00\n00:f7:42\n```\n\nWhich contaains:\n* A 9 bytes string containing 'BLOCKDATA'\n* 3 repeating records of 17 bytes containing a 1 byte integer ID, a 15 bytes \nstring NAME and a 1 byte interger ACTIVE flag\n* 19 bytes containing a 15 bytes string AUTHOR, a 2 bytes integer ID and a \n2 bytes bigendian signed integer POINTS.\n\nFirst create the data handler with the data.\n\n```python\ndata = b'BLOCKDATAdJamie Cash     \\x01eBobby Smith    \\x00fMr Bean        '\\\n      +b'\\x01Mr Author      \\n\\x00\\xff\\xec\\x00\\x00\\xf7B'\n\nhandler = bd.DataHandler(data)\n```\n\nThe name from the first record can be read by creating a variable, specifying a\nname for the variable, it's size, it's datatye and it's offset.\n\n```python\nprint(\"Name: \" + handler.read_variable(bd.Variable('name', 15, str, 10)))\n```\n\n```\nName: Jamie Cash\n```\n\nThe 19 bytes of author data starting at offset 60 can be read into a Pandas \nDataFrame by specifying the layout of the structure, including its variables. \nThe DataHandler can then be used to read it.\n\n```python\nauthor_struct = \\\n      bd.Structure(60, [bd.Variable('AUTHOR', 15, str), \n                        bd.Variable('ID', 2, int), \n                        bd.Variable('POINTS', 2, int, \n                                    byteorder=bd.ByteOrder.BIG, signed=True)])\nhandler.add_structure('author', author_struct)\ndf = handler.read_structure('author')\ndf\n```\n![image](https://github.com/jamiecash/binda/raw/main/example/img/single_structure.png)\n\nThe three row repeating structure can be read in a similar way, but this time\nalso specifying the number of rows.\n\n```python\npeople_struct = \\\n  bd.Structure(9, [bd.Variable('ID', 1, int),\n                    bd.Variable('NAME', 15, str),\n                    bd.Variable('ACTIVE', 1, bool)], rows=3)\n\nhandler.add_structure('people', people_struct)\ndf = handler.read_structure('people')\ndf\n```\n\n![image](https://github.com/jamiecash/binda/raw/main/example/img/repeating_structure.png)\n\nThe dataframe can be edited, and saved back to edit the binary data.\n\n```python\n# Change Bobby Smiths name to Bobby Smythe, his ID to 200 and is active \n# status to True\ndf.loc[df['ID'] == 101, 'ID'] = 200\ndf.loc[df['ID'] == 200, 'NAME'] = 'Bobby Smythe   '\ndf.loc[df['ID'] == 200, 'ACTIVE'] = True\nhandler.write_structure('people', df)\n\n# Confirm that the change has been made to the data by re-reading it and \n# displaying\ndf = handler.read_structure('people')\ndf\n```\n\n![image](https://github.com/jamiecash/binda/raw/main/example/img/repeating_structure_changed.png)\n\nWe can also check the binary data to see the change.\n```python\nprint(handler.data[26:43])\n```\n\n```\nb'\\xc8Bobby Smythe   \\x01'\n```\n\n## Examples\n\n2 Jupyter notebooks are provided in the examples folder, one containing the code \nfrom the **Usage** section above and one containing an example on reading and \nwritimg Exif data to a .jpeg file.\n\n## Joining the Project Team\n\nThis project is maintained on [GitHub](https://github.com/jamiecash/binda):\n\nIf you would like to contribute to this project by fixing issues or adding \nfeatures, please follow the below steps:\n* If adding functionality or fixing an issue not already raised on GitHub, raise \nan issue.\n* Assign the issue(s) to yourself.\n* Fork the project.\n* Create a branch from master.\n* Make the required changes to the project in your local branch.\n* Commit your changes, adding comments referencing the issues that your changes \nfix.\n* Push this branch to your GitHub project.\n* Open a Pull Request on GitHub.\n* Email me at jlcash@gmail.com to discuss the changes made.\n* Once changes have been agreed, I will merge or close the pull request.\n* Sync the updated master back to your fork.\n* Close the issues that were fixed.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Jamie Cash  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Read and write binary data using Pandas",
    "version": "1.0.22",
    "project_urls": {
        "Bug Tracker": "https://github.com/jamiecash/binda/issues",
        "Documentation": "https://jamiecash.github.io/binda/binda.html",
        "Homepage": "https://github.com/jamiecash/binda"
    },
    "split_keywords": [
        "analytics",
        "binary",
        "data",
        "hex",
        "hexadecimal",
        "pandas"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "898dff9b7b57da8f754bceda13e1a494361824daabdd86665828e03e2333622a",
                "md5": "1a4287588029cdb6efc1538c36714e89",
                "sha256": "57a542c21d37b271109759d2c37aed4eff73789d03e88714571d5ea0fe616367"
            },
            "downloads": -1,
            "filename": "binda-1.0.22-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1a4287588029cdb6efc1538c36714e89",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6962556,
            "upload_time": "2023-10-02T13:31:27",
            "upload_time_iso_8601": "2023-10-02T13:31:27.577999Z",
            "url": "https://files.pythonhosted.org/packages/89/8d/ff9b7b57da8f754bceda13e1a494361824daabdd86665828e03e2333622a/binda-1.0.22-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bd64d00fbe3d2e07e8d7bbd73e17acd8da834c98e9850b855c00b8aa7b4733e7",
                "md5": "07d7c7718e4430a7b94eb0181b1e657c",
                "sha256": "4c902a5cf5034eaf9e88e1ad04e9108121da72dc1c2ea71cd3520a1f3fff7691"
            },
            "downloads": -1,
            "filename": "binda-1.0.22.tar.gz",
            "has_sig": false,
            "md5_digest": "07d7c7718e4430a7b94eb0181b1e657c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 6962437,
            "upload_time": "2023-10-02T13:31:30",
            "upload_time_iso_8601": "2023-10-02T13:31:30.393478Z",
            "url": "https://files.pythonhosted.org/packages/bd/64/d00fbe3d2e07e8d7bbd73e17acd8da834c98e9850b855c00b8aa7b4733e7/binda-1.0.22.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-02 13:31:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jamiecash",
    "github_project": "binda",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "binda"
}
        
Elapsed time: 0.15924s