> For the complete documentation index, see [llms.txt](https://docs.bayunsystems.com/bayuncoresdk-python/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bayunsystems.com/bayuncoresdk-python/bayuncoresdk-operations/lock-unlock-file.md).

# 5.1 Lock/Unlock File

## &#x35;**.1.1 Lock File**

The `lockFile` function of `BayunCore` class locks a file with default encryption-policy dictated by server settings.

The function takes the following parameters :

* **sessionId** : Unique SessionId which is received in the authenticate function response.
* **filePath** : File path to be locked.

The file at the given file path is overwritten with the locked file. If file locking fails original file is not changed.

{% tabs %}
{% tab title="Python" %}

```python
lockedFilePath = bayunCore.lockFile("<sessionId>", <"filePath">)
```

{% endtab %}
{% endtabs %}

## **5.1.2 Lock File with encryption-policy**

The `lockFile` function with encryption-policy as an optional parameter locks file with the encryption key dictated by the policy. The function takes the following parameters :

* **sessionId** : Unique SessionId which is received in the authenticate function response.
* **filePath** : File path to be locked.
* **encryptionPolicy** : [BayunEncryptionPolicy](https://docs.bayunsystems.com/bayuncoresdk-python/bayuncoresdk-operations#encryption-policy) determines the key for locking.
* **keyGenerationPolicy** : [BayunKeyGenerationPolicy](https://docs.bayunsystems.com/bayuncoresdk-python/bayuncoresdk-operations#key-generation-policy) determines the policy to generate the data encryption key.
* **groupId** : GroupId is required if encryptionPolicy is `BayunEncryptionPolicyGroup`.

{% hint style="info" %}
If encryption-policy is other than `BayunEncryptionPolicyGroup` then groupId should be empty string.
{% endhint %}

{% tabs %}
{% tab title="Python" %}

```python
from BayunCore import BayunEncryptionPolicy
from BayunCore import BayunKeyGenerationPolicy

encryptionPolicy = BayunEncryptionPolicy.Company
keyGenerationPolicy = BayunKeyGenerationPolicy.Static
filePath = "<file path>"
lockedFilePath = bayunCore.lockFile("<sessionId>", filePath, encryptionPolicy, keyGenerationPolicy, "<groupId>")
```

{% endtab %}
{% endtabs %}

## **5.1.3 Unlock File**

The `unlockFile` function of `BayunCore` class unlocks a locked file. The function takes the following parameters :

* **sessionId** : Unique SessionId which is received in the authenticate function response.
* **filePath** : File path to be unlocked.

The file at the given file path is overwritten with the unlocked file.

{% tabs %}
{% tab title="Python" %}

```python
unlockedFilePath = bayunCore.unlockFile("<sessionId>","<filePath>")
```

{% endtab %}
{% endtabs %}
