Skip to main content

To fetch data from API and import to SQL Server in Python

Project description

PyDataImport

A Python package for importing data from various sources to SQL Server databases.

Installation

You can install the package using pip:

pip install pydataimport

Usage

import pydataimport as pdi

# Import data from JSON
pdi.import_data(
    "json",
    data_source,
    "table_name",
    operation_mode=pdi.OPERATION_MODE['SINGLE_INSERT']
)

# Fetch data from database
data = pdi.fetch_data("SELECT * FROM your_table")

# Get current date in string format
current_date = pdi.date_str_now()

# Track script runtime
with pdi.track_script_runtime() as timer:
    # Your code here
    pass

Features

  • Data import from various sources (JSON, CSV, etc.)
  • Database operations (fetch, execute stored procedures)
  • Utility functions for date handling
  • Script runtime tracking
  • Environment configuration management

Configuration

The package uses environment variables for configuration. Create a .env file with the following variables:

# API Configuration
DATA_SRC_API_ENDPOINT=your_api_endpoint
DATA_SRC_TOKEN=your_api_token

# Database Configuration
DATA_DES_CONNECTION_TYPE=window  # or 'remote' for SQL authentication
DATA_DES_SERVER=your_server
DATA_DES_DB_NAME=your_database
DATA_DES_PORT=1433
DATA_DES_USERNAME=your_username
DATA_DES_PASSWORD=your_password
DATA_DES_DRIVER=SQL Server Native Client 11.0  # or your preferred SQL Server driver
DATA_DES_TABLE=your_table
DATA_DES_STORED_PROCEDURE=your_stored_procedure

# Operation Mode
OPERATION_MODE=DROP_OLD_CREATE_NEW

SQL Server Driver Configuration

The package uses pyodbc to connect to SQL Server. You need to specify the correct driver name in the DATA_DES_DRIVER environment variable. Common driver names include:

  • SQL Server Native Client 11.0
  • ODBC Driver 17 for SQL Server
  • ODBC Driver 18 for SQL Server

To find available drivers on your system, you can run:

import pyodbc
print(pyodbc.drivers())

Requirements

  • Python 3.8 or higher
  • SQL Server database
  • Required Python packages (automatically installed with pip):
    • pandas
    • pyodbc
    • requests
    • python-dateutil
    • numpy

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

pydataimport-0.1.2.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

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

pydataimport-0.1.2-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

Details for the file pydataimport-0.1.2.tar.gz.

File metadata

  • Download URL: pydataimport-0.1.2.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for pydataimport-0.1.2.tar.gz
Algorithm Hash digest
SHA256 447dbb2692e465e9b7f9278e13bd4fa8224aa518e2e21d097e3e65868386091e
MD5 427342b74091c39d4b91632d6b051d6f
BLAKE2b-256 b26f9ec0fd1e013ec7639c1cbe9fa19050c02a05236d34e9a26144e311c96a41

See more details on using hashes here.

File details

Details for the file pydataimport-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pydataimport-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 37.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for pydataimport-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9c98f2e20cb49ac9e6ba59a277901ab058be87b4fd1e651b2b7d38cc7bcd4551
MD5 3eb2e7c64aa3a94a84e8e276823f2277
BLAKE2b-256 871f8023e7f13763cefd7077cccc11750a8bd3420adc6a8ad44297e21f6fa1b3

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