Skip to main content

A library that simplifies CRUD operations with database.

Reason this release was yanked:

import conflict

Project description

AlchemyLite

A library that simplifies CRUD operations with PostgreSQL database.

What is new in 1.2.0 release?

Full docs 1.This release adds support for SQLite database

from alchemylite.sync import SyncCrud, SyncSqliteConfig

config = SyncSqliteConfig(db_path=ABSOLUTE_DB_PATH)
crud = SyncCrud(config, model, model.base)     
  1. Changing method names The names of some methods have been changed
  • AsyncCrudOperation -> AsyncCrud
  • SyncCrudOperation -> SyncCrud
  • delete_all_tables -> delete_table
  • create_all_tables -> create_table
  1. Configuration classes are divided by database type
    Asynchronous approach:
  • from alchemylite.async_ import AsyncPostgresConfig (for postgresql)
  • from alchemylite.async_ import AsyncSqliteConfig (for sqlite)
    Synchronous approach:
  • from alchemylite.sync import SyncPostgresConfig (for postgresql)
  • from alchemylite.sync import SyncSqliteConfig (for sqlite)

How to use it?

First, install the library with the command pip install AlchemyLite
First you need to create a configuration in which you need to register the database parameters
For synchronous operation

from alchemylite.sync impoty SyncPostgresConfig

config = SyncConfig(
    db_host="your_host",
    db_port="your_port",
    db_user="your_user",
    db_pass="your_password",
    db_name="your_db_name"
)

Then, we create a class to which we pass our configuration, model class and base class of model

from alchemylite.sync import SyncCrud

crud = SyncCrud(
    config, YourModel, Base
)

For async operation

from alchemylite.async_ import AsyncPostgresConfig, AsyncCrud

config = AsyncPostgresConfig(
    db_host="your_host",
    db_port="your_port",
    db_user="your_user",
    db_pass="your_password",
    db_name="your_db_name"
)

crud = AsyncCrud(
    config, YourModel, Base
)

How to perform CRUD operations?

The library supports the following methods

  • create - Creates new data in the table.
  • read_all - Reads all data from a table.
  • limited_read - Reads a certain amount of data. Default values: limit = 50, offset = 0
  • read_by_id - Reads all data from a table by id
  • update_by_id - Update data by id
  • delete_by_id - Delete data by id
  • create_all_tables - Creates all tables in database
  • delete_all_tables - Delete all tables in database

Examples of use

from alchemylite.sync import SyncCrud, SyncPostgresConfig 
from sqlalchemy.orm import Mapped, mapped_column, DeclarativeBase


config = SyncPostgresConfig(
    db_host="localhost",
    db_port="5432",
    db_user="postgres",
    db_pass="postgres",
    db_name="alchemylite"
)


class Base(DeclarativeBase):
    pass
    
    
class User(Base):
    __tablename__ = "users"
    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str]
    email: Mapped[str]
   

crud = SyncCrud(
    config, User, Base
)

crud.create_all_tables()
crud.create(name="User", email="email@mail.ru")
print(crud.read_all())
print(crud.limited_read(limit=5, offset=0))
print(crud.read_by_id(id=1))
crud.update_by_id(id=1, name="new value", email="new_emal")
crud.delete_by_id(id=1)
crud.delete_all_tables()

The library will be supported, this is the first version for now. New features will be added in the future.

If you have suggestions for improvements or any comments, I'm ready to listen to you

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

alchemylite-1.2.1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

AlchemyLite-1.2.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file alchemylite-1.2.1.tar.gz.

File metadata

  • Download URL: alchemylite-1.2.1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.4

File hashes

Hashes for alchemylite-1.2.1.tar.gz
Algorithm Hash digest
SHA256 344c841a80376ad32603897380d857a0be2e745ff313097666f5ece5d6843efc
MD5 7901f4a24ec0dad331f5775a3b3dcf30
BLAKE2b-256 e7eba14f0b46c6d278c831f0b8fdb0d03394e7c49efa3d8ed21fd30bec79f336

See more details on using hashes here.

File details

Details for the file AlchemyLite-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: AlchemyLite-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.4

File hashes

Hashes for AlchemyLite-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb545fef7c970eb6ff373bba146a4bec0900e87a72732f1001f54cbc11033c33
MD5 745bccbb70a7c90b68de815c96cf3377
BLAKE2b-256 15798308f54d419446b330f6bf317983c3498e03a6950f56a7e04fc07291331b

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