Skip to main content

Convenient access to the NextBrain API from python

Project description

NextBrain

Convenient access to the NextBrain API from python

Installation

pip install nextbrain

If you want to use the async version you need to install asyncio and aiohttp:

pip install asyncio aiohttp

Normal usage

All steps in one.

from nextbrain import NextBrain
from typing import Any, List

def main():
    nb = NextBrain('<YOUR-ACCESS-TOKEN-HERE>')

    # You can create your custom matrix and predict matrix by your own from any source
    matrix: List[List[Any]] = nb.load_csv('<PATH-TO-YOUR-TRAINING-CSV>')
    predict_matrix: List[List[Any]] = nb.load_csv('<PATH-TO-YOUR-PREDICTING-CSV>')

    model_id, response = nb.upload_and_predict(matrix, predict_matrix, '<YOUR-TARGET-COLUMN>')
    # model_id is also returned in order to predict multiple times against same model
    print(response)

if __name__ == '__main__':
    main()

Step by step

from nextbrain import NextBrain
from typing import Any, List

def main():
    nb = NextBrain('<YOUR-ACCESS-TOKEN-HERE>')

    # You can create your custom matrix and predict matrix by your own from any source
    matrix: List[List[Any]] = nb.load_csv('<PATH-TO-YOUR-TRAINING-CSV>')
    # Upload the model to NextBrain service
    model_id: str = nb.upload_model(matrix)
    # Train the model
    # You can re-train a previous model
    nb.train_model(model_id, '<YOUR-TARGET-COLUMN>')

    predict_matrix: List[List[Any]] = nb.load_csv('<PATH-TO-YOUR-PREDICTING-CSV>')
    # You can predict multiple using the same model (don't need to create a new model each time)
    response = nb.predict_model(model_id, predict_matrix[0], predict_matrix[1:])
    print(response)

if __name__ == '__main__':
    main()

Async usage

All steps in one.

from nextbrain import AsyncNextBrain
from typing import Any, List

async def main():
    nb = AsyncNextBrain('<YOUR-ACCESS-TOKEN-HERE>')

    # You can create your custom matrix and predict matrix by your own from any source
    matrix: List[List[Any]] = nb.load_csv('<PATH-TO-YOUR-TRAINING-CSV>')
    predict_matrix: List[List[Any]] = nb.load_csv('<PATH-TO-YOUR-PREDICTING-CSV>')

    model_id, response = await nb.upload_and_predict(matrix, predict_matrix, '<YOUR-TARGET-COLUMN>')
    # model_id is also returned in order to predict multiple times against same model
    print(response)

if __name__ == '__main__':
    import asyncio
    asyncio.run(main())

Step by step

from nextbrain import AsyncNextBrain
from typing import Any, List

async def main():
    nb = AsyncNextBrain('<YOUR-ACCESS-TOKEN-HERE>')

    # You can create your custom matrix and predict matrix by your own from any source
    matrix: List[List[Any]] = nb.load_csv('<PATH-TO-YOUR-TRAINING-CSV>')
    # Upload the model to NextBrain service
    model_id: str = await nb.upload_model(matrix)
    # Train the model
    # You can re-train a previous model
    await nb.train_model(model_id, '<YOUR-TARGET-COLUMN>')

    predict_matrix: List[List[Any]] = nb.load_csv('<PATH-TO-YOUR-PREDICTING-CSV>')
    # You can predict multiple using the same model (don't need to create a new model each time)
    response = await nb.predict_model(model_id, predict_matrix[0], predict_matrix[1:])
    print(response)

if __name__ == '__main__':
    import asyncio
    asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nextbrain-0.1.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nextbrain-0.1.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file nextbrain-0.1.1.tar.gz.

File metadata

  • Download URL: nextbrain-0.1.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.9.5 Linux/5.15.0-56-generic

File hashes

Hashes for nextbrain-0.1.1.tar.gz
Algorithm Hash digest
SHA256 23f0e072c1ba9eff2247d4708b3d5260b99afea9e68ede62ae142c5e625888d8
MD5 07e1f58f5d510ff8af27c8eb89e71ddf
BLAKE2b-256 dacc7bf3263ec954885567ac6040510bed267a52bf8893896862e332c5548590

See more details on using hashes here.

File details

Details for the file nextbrain-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nextbrain-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.9.5 Linux/5.15.0-56-generic

File hashes

Hashes for nextbrain-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e972ae52c895da986ad6ef631a4d2dc05bf4c339ae5742b5600fd023b050854f
MD5 40b8d0a6b484f632223e342692efa6e3
BLAKE2b-256 6be6d7378b3fde3e8fb1df3c36541b6af9e08fb3e0706ce24813ecd1e09b3563

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page