Giter Site home page Giter Site logo

deta.py's Introduction

deta.py

An async library to interact with deta base & drive.

Community

Table of Contents

Installation

Python 3.8+ recommended

pip install git+https://github.com/jnsougata/deta.py

Quick Start

import deta
import asyncio


async def main():
  service = deta.Deta(DETA_PROJECT_KEY)

  # instantiating a base
  base = service.base(name='TEST_BASE')

  # instantiating a drive
  drive = service.drive(name='TEST_DRIVE')

  # put single json deta base
  await base.put(
    deta.Record({'name': 'John Doe', 'age': 20}, key='xyz', expire_after=100)
  )

  # or put multiple records with a single request
  await base.put(
    deta.Record({'name': 'John Doe 0', 'age': 20}, key='xyz_1', expire_after=100),
    deta.Record({'name': 'John Doe 1', 'age': 21}, key='xyz_2', expire_after=100),
    deta.Record({'name': 'John Doe 2', 'age': 22}, key='xyz_3', expire_after=100)
  )

  # doing queries
  q = deta.Query()
  q.equals("name", "John")
  q.equals("address.city", "New York")
  q.range("age", 18, 30)
  q.not_equals("position", "Manager")
  q.contains("id", "-")
  results = await base.fetch([q])
  print(results)

  # updating records
  u = deta.Updater()
  u.set("inactive", True)
  u.increment("age")
  u.delete("address")
  await base.update("user_777", u)

  # downloading a song stored in deta drive
  stream = await drive.get('song.mp3')
  async for chunk, _ in stream.iter_chunks():
    # do something with the chunk
    ...

    # or read the entire file
    content = await stream.read()
    # do something with the content

  # closing deta connection
  await service.close()


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

Async Context Manager

import deta

async def main():
    async with deta.Deta(DETA_PROJECT_KEY) as service:
        base = service.base('TEST_BASE')
        print(await base.get())

        drive = service.drive('TEST_DRIVE')
        stream = await drive.get('song.mp3')
        with open('song.mp3', 'wb') as f:
            f.write(await stream.read())

Documentation

Read the documentation for more information.

deta.py's People

Contributors

imptype avatar jnsougata avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.