> For the complete documentation index, see [llms.txt](https://docs.neuralaim.ru/napi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.neuralaim.ru/napi/programmy-or-primery/svoi-python-skript-s-napi.md).

# Свой python скрипт с NAPI

## Код:

<pre class="language-python"><code class="lang-python"><strong>SERVER_PORT = 64200 # Константа указывающая порт для работы сервера вашего NAPI
</strong><strong>BUFFER_SIZE = 1024 #Константа для буфера сервера
</strong>BUFFER_SIZE = FOV * FOV * 3 # Высчитываем буфер для отправки изображения на клиент.
<strong>server.send('Hello!') # Отправляем информация в другую программу
</strong><strong>data = server.recv() # Получаем информацию от скрипта
</strong><strong>server.close() # Закрываем сервер
</strong></code></pre>

{% hint style="info" %}
Используйте этот пример для соединения вашего скрипта python со скриптом NAPI.
{% endhint %}

{% hint style="warning" %}
Рекомендуем устанавливать BUFFER\_SIZE равному кол-во данных для передачи, чтобы передать всё за один "пакет" и получить максимальную скорость.
{% endhint %}

### Код для клиентской части python кода.

```python
import socket

class Client:
    def __init__(self, host='127.0.0.1', port=65432):
        self.host = host
        self.port = port
        self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.s.connect((self.host, self.port))

    def send(self, data):
        self.s.sendall(data.encode('utf-8'))

    def recv(self, buffer_size=1024):
        data = self.s.recv(buffer_size)
        return data.decode('utf-8')

    def close(self):
        self.s.close()

if __name__ == "__main__":
    c = Client()
    c.send('hello')
    data = c.recv()
    print(f"Получено от сервера: {data}")
    c.close()
```

{% hint style="info" %}
Вы также можете отредактировать клиентскую часть, но изменения на серверную часть NAPI, увы внести нельзя. Но вы можете попросить об этом - [@neuraluser](https://t.me/neuraluser).
{% endhint %}


---

# 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:

```
GET https://docs.neuralaim.ru/napi/programmy-or-primery/svoi-python-skript-s-napi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
