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. Generate them programatically.

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

source_database = "source_database"
source_schema = "source_schema"

destination_database = "destination_database"
destination_schema = "destination_schema"

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"),
]

table_and_key = {
    "FactTable": "FactKey",
    "Dimensiontable": "DimensionKey"
}
tables = {}

for name, key in table_and_key.items():
    tables[name] = Table(
        source_path=Path(database=source_database, schema=source_schema, table=name),
        destination_path=Path(database=destination_database, schema=destination_schema, table=name),
        source_data_modified_column_name="RowUpdatedAt",
        timezone=SqlServerTimeZone.CENTRAL_EUROPEAN_STANDARD_TIME,
        default_columns=DEFAULT_COLUMNS,
        write_mode=WriteMode.APPEND,
        batch_size=200,
        unique_columns=[
            Column(
                name=f"{key}",
                data_type=SqlServerDataType.NVARCHAR.with_length(50),
                constraints="NOT NULL",
            )
        ],
        indexes=[
            Index(
                index_type=SqlServerIndexType.NONCLUSTERED,
                columns=[DATA_MODIFIED]
            )
        ]
    )

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.3.0.tar.gz (9.4 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.3.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for aftonfalk-1.3.0.tar.gz
Algorithm Hash digest
SHA256 ba7e2c8409c9a223c459d652fc7edcaa83b5b70f53cda296f466282f0e8df235
MD5 2b8ee5d20cc2192eba1e6c4858b72b97
BLAKE2b-256 d4de47e5ba947e7c2442165888cd8bcea2f8f693654740dbdf7bacb22c27acc0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aftonfalk-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d509ec4aab04b31e12612f587c4e3e910d91e5aed137169d0f4241aeb668ce7
MD5 6fa56e4a985aa1fe5b42f79528f6fee7
BLAKE2b-256 ca1f57779fffdd68b6229ee4a178b35dd03a1d32c7c73d73c6a045a60ae418cb

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