Skip to main content

Makes it easier to interact with sql server using python

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Aftonfalk

Aftonfalk is a module that makes it easier to interact with microsoft sql server. You can see it as an extension to pyodbc

How to install

pip install aftonfalk

Example usage

Instantiate a driver:

driver = MssqlDriver(
    dsn="mssql://sa:Password1!@host.docker.internal:31433",
    driver=r"{ODBC Driver 18 for SQL Server}"
)

Dropping a table using execute

driver.execute(sql=f"DROP TABLE source_system.schema.table;")

read & write data

data = driver.read(query="select * from tablex")
driver.write(sql="INSERT INTO tablex (column_name) VALUES ('column_value')", data=data)

Manage tables.

from aftonfalk.mssql.enums_ import SqlServerDataType, SqlServerIndexType, SqlServerTimeZone, WriteMode
from aftonfalk.mssql.types_ import Column, Table, Index


source_database = "source_database"
source_schema = "source_schema"
destination_database = "destination_database"
destination_schema = "destination_schema"

TIMEZONE = SqlServerTimeZone.CENTRAL_EUROPEAN_STANDARD_TIME

WRITE_MODE = WriteMode.APPEND

DATA_MODIFIED = Column(name="data_modified", data_type="DATETIMEOFFSET", constraints="NOT NULL")

DEFAULT_COLUMNS = [
    Column(name="metadata_modified", data_type="DATETIMEOFFSET", constraints="NOT NULL"),
    DATA_MODIFIED,
    Column(name="data", data_type="NVARCHAR(MAX)", constraints="NOT NULL"),
]
INDEXES = [
    Index(
        name="data_modified_nc",
        index_type=SqlServerIndexType.NONCLUSTERED,
        columns=[DATA_MODIFIED],
    )
]

tables = {
    "table": Table(
        source_path=f"{source_database}.{source_schema}.table",
        destination_path=f"{destination_database}.{destination_schema}.table",
        source_data_modified_column_name="credat",
        timezone=TIMEZONE,
        write_mode=WRITE_MODE,
        default_columns=DEFAULT_COLUMNS,
        unique_columns=[
            Column(
                name="table_code",
                data_type=SqlServerDataType.NVARCHAR.with_length(50),
                constraints="NOT NULL",
            )
        ],
        indexes=INDEXES
    )
}

then you can do things like easily:

creating tables

driver.create_table(path=table.destination_path, ddl=table.table_ddl())

inserting into tables

data = ...
driver.write(sql=table.insert_sql(), data=data)

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

aftonfalk-1.1.2.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

aftonfalk-1.1.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file aftonfalk-1.1.2.tar.gz.

File metadata

  • Download URL: aftonfalk-1.1.2.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for aftonfalk-1.1.2.tar.gz
Algorithm Hash digest
SHA256 4e97b35c0f11df1018cb12467b0fb02bd478f8d224afd128286b604b464a37cb
MD5 653196256d307b1106d7fdc47b31a63b
BLAKE2b-256 b800099b9c6d64d43f6ab8bf0a2e2f0406819170e9708daf49be745f14e688e2

See more details on using hashes here.

File details

Details for the file aftonfalk-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: aftonfalk-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for aftonfalk-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 20a5c881b60e79b810817bfed539d897e5721e163f17a0b9be6d9523fbb79fd8
MD5 0e3c4399df8b3beea867a800550ff2f5
BLAKE2b-256 bf18e714169123760ecba90fe3be0627d5b9bade6dd7efe5d6a0d9c065baab45

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