Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 720705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:47:22+00:00 2026-05-14T05:47:22+00:00

I have a set of .csv files that I want to process. It would

  • 0

I have a set of .csv files that I want to process. It would be far easier to process it with SQL queries. I wonder if there is some way to load a .csv file and use SQL language to look into it with a scripting language like python or ruby. Loading it with something similar to ActiveRecord would be awesome.

The problem is that I don’t want to have to run a database somewhere prior to running my script. I souldn’t have additionnal installations needed outside of the scripting language and some modules.

My question is which language and what modules should I use for this task. I looked around and can’t find anything that suits my need. Is it even possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:47:22+00:00Added an answer on May 14, 2026 at 5:47 am

    There’s sqlite3, included into python. With it you can create a database (on memory) and add rows to it, and perform SQL queries.

    If you want neat ActiveRecord-like functionality you should add an external ORM, like sqlalchemy. That’s a separate download though

    Quick example using sqlalchemy:

    from sqlalchemy import create_engine, Column, String, Integer, MetaData, Table
    from sqlalchemy.orm import mapper, create_session
    import csv
    CSV_FILE = 'foo.csv'
    engine = create_engine('sqlite://') # memory-only database
    
    table = None
    metadata = MetaData(bind=engine)
    with open(CSV_FILE) as f:
        # assume first line is header
        cf = csv.DictReader(f, delimiter=',')
        for row in cf:
            if table is None:
                # create the table
                table = Table('foo', metadata, 
                    Column('id', Integer, primary_key=True),
                    *(Column(rowname, String()) for rowname in row.keys()))
                table.create()
            # insert data into the table
            table.insert().values(**row).execute()
    
    class CsvTable(object): pass
    mapper(CsvTable, table)
    session = create_session(bind=engine, autocommit=False, autoflush=True)
    

    Now you can query the database, filtering by any field, etc.

    Suppose you run the code above on this csv:

    name,age,nickname
    nosklo,32,nosklo
    Afila Tun,32,afilatun
    Foo Bar,33,baz
    

    That will create and populate a table in memory with fields name, age, nickname. You can then query the table:

    for r in session.query(CsvTable).filter(CsvTable.age == '32'):
        print r.name, r.age, r.nickname
    

    That will automatically create and run a SELECT query and return the correct rows.

    Another advantage of using sqlalchemy is that, if you decide to use another, more powerful database in the future, you can do so pratically without changing the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some CSV data files that I want to import into mySQL. I
I have Java desktop application that works with CSV files. And i want add
I have a set of 10 CSV files, which normally have a an entry
I have some really lame Csv files I need to parse. I am using
I have a JMeter test that uses a CSV Data Set Config to provide
I have a CSV file that I want to make available for my Android
I have a gridview that I want to export to a .csv file. I
I have a PHP script that uploads a CSV file and then saves some
I have a huge set of data that I want to insert into the
I have a automated (Visual Build) build process that runs: A set of automated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.