> For the complete documentation index, see [llms.txt](https://docs.macilib.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.macilib.org/docs/tools/hash-functions/maci.createfilehash.md).

# maci.createfilehash

Creates a hash of any file, and stores the hash data to a newly created file. Always returns a string of the file hash. Useful to use alongside its partner function as mentioned below.

{% hint style="info" %}
maci.createfilehash  ->  str
{% endhint %}

*Basic Example of hashing a file and storing its hash using default positional parameters*

```python
maci.createfilehash(src_file, dst_file)
```

In this example, we simply input the source file to hash and the destination file to store the hash data using the createfilehash function and pass the file locations as arguments to the function, and the hashed data is then stored to the destination file.

This tool is **encouraged to be used alongside its partner function** [comparefilehash](/docs/tools/hash-functions/maci.comparefilehash.md), which will automatically handle comparing the hash data stored against the source file hashed and return a Trur/False if they match.

#### disable creating destination file

createfilehash always returns the hash of the source file to a string if needing to store it in code whether you create a destination file or not. However, you may also disable the need for a destination file to store the hash by setting the file\_to\_store\_hash parameter to None.

*Example disabling creating a destination file and just collecting the hash*

```python
data = maci.createfilehash(src_file, None)
```

### partner functions

Functions that are related for createfilehash

[maci.comparefilehash](/docs/tools/hash-functions/maci.comparefilehash.md)  ->  Compares previously created file with stored hash with the source file hash

### parameters & arguments

Describes all parameter functionality and accepted data types

<details>

<summary>file_to_hash:  str | Path</summary>

First required positional argument. Accepts strings and [Path objects](https://docs.python.org/3/library/pathlib.html)

Use this parameter to point to your source filepath to get the hash.

</details>

<details>

<summary>file_to_store_hash:  str | Path | None</summary>

Second required positional argument. Accepts strings, [Path objects](https://docs.python.org/3/library/pathlib.html), and None

Use this parameter to point to your destination filepath to store hash of the source file. Set to None if you do not want a file created to store hash.

</details>

<details>

<summary>hash_algorithm:  str</summary>

Optional parameter. Accepts strings. Default = 'sha256'

Use this parameter to set the hash algorithm used for the hash. Default is sha256, which is a current common industry standard.

All options available: 'sha256', 'sha512', 'sha384', 'sha1', 'md5'

</details>

<details>

<summary>encoding:  str | None  <em><strong>(Removed in v.1.1.1)</strong></em></summary>

Optional parameter. Accepts strings or None. Default = None

Use this parameter to set the source file hashed data and destination file with the desired codec if needed. The default uses the default of python, so you don't have to use this, but you can if the data needs to be written with a specific codec.

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.macilib.org/docs/tools/hash-functions/maci.createfilehash.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
