django-binhash


Namedjango-binhash JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/racum/django-binhash
SummaryWork with hexadecimal, store in binary, using half of the data size.
upload_time2024-07-09 12:34:35
maintainerNone
docs_urlNone
authorRonaldo Racum
requires_python>=3.10
licenseBSD-3-Clause
keywords binhash
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django Binary Hash Fields

Work with hexadecimal, store in binary, using half of the data size.

## Installation

Just install via `pip`:

```
pip install django-binhash
```

And add to your apps on `settings.py`:

```python
INSTALLED_APPS = [
    # Django apps
    'binhash',
    # Your apps
]
```
## Compatibility

### Environments

Tested under Python from 3.10 to 3.12, and under Django 4.x and 5.x.

### Databases

At the version `0.2.0` it was only tested on SQLite, but if should work fine in all databases officially supported by Django.

### Formats

* MD5
	* `MD5Field`
* SHA-1
	* `SHA1Field`
* SHA-2
	* `SHA224Field`
	* `SHA256Field`
	* `SHA384Field`
	* `SHA512Field`
* SHA-3
	* `SHA3_224Field`
	* `SHA3_256Field`
	* `SHA3_384Field`
	* `SHA3_512Field`
	* `SHAKE128Field`
	* `SHAKE256Field`
	* `SHAKE512Field`

## Usage

Just import and set some fields:

```python
from django.db import models
from binhash import (MD5Field, SHA1Field, SHA256Field)

class ISOFile(models.Model):
    name = models.CharField('Name', max_length=30)
    url = models.URLField('URL')
    md5sum = MD5Field('MD5 Checksum')
    sha1sum = SHA1Field('SHA-1 Checksum')
    sha256sum = SHA256Field('SHA-256 Checksum')
```

Than, proceed using them like CharFields:

```python
# Create normaly as if the fields were strings:
ISOFile.objects.create(
    name='Ubuntu Server 17.04',
    md5sum='d02df11b4a7318b7250824f6d0bab9c0',
    sha1sum='bc5fb639724b5cd90eb739845f246e2c564b0dd8',
    sha256sum='632e64dde9a7da27fa96bea4d2cf78f051065c6becc0d0f728aabfc091396256',
)

# Fetch by string is also supported:
ubuntu = ISOFile.objects.get(md5sum='d02df11b4a7318b7250824f6d0bab9c0')

# Everything works as expected on the application side:
print(ubuntu.sha1sum)  # Shows bc5fb639724b5cd90eb739845f246e2c564b0dd8
print(type(ubuntu.sha1sum))  # Shows <class 'str'>

```

If you are feeling skeptical, check the database:

```
$ ./manage.py dbshell
sqlite> .header on
sqlite> .mode column
sqlite> select hex(sha1sum) hex_sha1,
   ...>        length(hex(sha1sum)) size_if_this_was_varchar,
   ...>        length(sha1sum) actual_size
   ...> from downloads_isofile;
hex_sha1                                  size_if_this_was_varchar  actual_size
----------------------------------------  ------------------------  -----------
BC5FB639724B5CD90EB739845F246E2C564B0DD8  40                        20

```

## License

This library is released under the **3-Clause BSD License**.

**tl;dr**: *"free to use as long as you credit me"*.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/racum/django-binhash",
    "name": "django-binhash",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "binhash",
    "author": "Ronaldo Racum",
    "author_email": "ronaldo@racum.com",
    "download_url": "https://files.pythonhosted.org/packages/ee/96/ff637ff6b4a8a20a4d66eaa9ee1f931cd5e949ad6a15c89eabc03f04193b/django_binhash-0.2.0.tar.gz",
    "platform": null,
    "description": "# Django Binary Hash Fields\n\nWork with hexadecimal, store in binary, using half of the data size.\n\n## Installation\n\nJust install via `pip`:\n\n```\npip install django-binhash\n```\n\nAnd add to your apps on `settings.py`:\n\n```python\nINSTALLED_APPS = [\n    # Django apps\n    'binhash',\n    # Your apps\n]\n```\n## Compatibility\n\n### Environments\n\nTested under Python from 3.10 to 3.12, and under Django 4.x and 5.x.\n\n### Databases\n\nAt the version `0.2.0` it was only tested on SQLite, but if should work fine in all databases officially supported by Django.\n\n### Formats\n\n* MD5\n\t* `MD5Field`\n* SHA-1\n\t* `SHA1Field`\n* SHA-2\n\t* `SHA224Field`\n\t* `SHA256Field`\n\t* `SHA384Field`\n\t* `SHA512Field`\n* SHA-3\n\t* `SHA3_224Field`\n\t* `SHA3_256Field`\n\t* `SHA3_384Field`\n\t* `SHA3_512Field`\n\t* `SHAKE128Field`\n\t* `SHAKE256Field`\n\t* `SHAKE512Field`\n\n## Usage\n\nJust import and set some fields:\n\n```python\nfrom django.db import models\nfrom binhash import (MD5Field, SHA1Field, SHA256Field)\n\nclass ISOFile(models.Model):\n    name = models.CharField('Name', max_length=30)\n    url = models.URLField('URL')\n    md5sum = MD5Field('MD5 Checksum')\n    sha1sum = SHA1Field('SHA-1 Checksum')\n    sha256sum = SHA256Field('SHA-256 Checksum')\n```\n\nThan, proceed using them like CharFields:\n\n```python\n# Create normaly as if the fields were strings:\nISOFile.objects.create(\n    name='Ubuntu Server 17.04',\n    md5sum='d02df11b4a7318b7250824f6d0bab9c0',\n    sha1sum='bc5fb639724b5cd90eb739845f246e2c564b0dd8',\n    sha256sum='632e64dde9a7da27fa96bea4d2cf78f051065c6becc0d0f728aabfc091396256',\n)\n\n# Fetch by string is also supported:\nubuntu = ISOFile.objects.get(md5sum='d02df11b4a7318b7250824f6d0bab9c0')\n\n# Everything works as expected on the application side:\nprint(ubuntu.sha1sum)  # Shows bc5fb639724b5cd90eb739845f246e2c564b0dd8\nprint(type(ubuntu.sha1sum))  # Shows <class 'str'>\n\n```\n\nIf you are feeling skeptical, check the database:\n\n```\n$ ./manage.py dbshell\nsqlite> .header on\nsqlite> .mode column\nsqlite> select hex(sha1sum) hex_sha1,\n   ...>        length(hex(sha1sum)) size_if_this_was_varchar,\n   ...>        length(sha1sum) actual_size\n   ...> from downloads_isofile;\nhex_sha1                                  size_if_this_was_varchar  actual_size\n----------------------------------------  ------------------------  -----------\nBC5FB639724B5CD90EB739845F246E2C564B0DD8  40                        20\n\n```\n\n## License\n\nThis library is released under the **3-Clause BSD License**.\n\n**tl;dr**: *\"free to use as long as you credit me\"*.\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Work with hexadecimal, store in binary, using half of the data size.",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/racum/django-binhash"
    },
    "split_keywords": [
        "binhash"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ee96ff637ff6b4a8a20a4d66eaa9ee1f931cd5e949ad6a15c89eabc03f04193b",
                "md5": "73ea63c922dd96511fba5c8df54cfc5a",
                "sha256": "08fb43dc4d34ce8b944181639db64b05d1c4b17380df83281ad49571509e1649"
            },
            "downloads": -1,
            "filename": "django_binhash-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "73ea63c922dd96511fba5c8df54cfc5a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 7544,
            "upload_time": "2024-07-09T12:34:35",
            "upload_time_iso_8601": "2024-07-09T12:34:35.968010Z",
            "url": "https://files.pythonhosted.org/packages/ee/96/ff637ff6b4a8a20a4d66eaa9ee1f931cd5e949ad6a15c89eabc03f04193b/django_binhash-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-09 12:34:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "racum",
    "github_project": "django-binhash",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "django-binhash"
}
        
Elapsed time: 0.99629s