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

  • Home
  • SEARCH
  • 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 8094203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:43:37+00:00 2026-06-05T20:43:37+00:00

I need to do some csv file processing in a django app. I heard

  • 0

I need to do some csv file processing in a django app.
I heard about csvkit and it looks pretty cool.
github page

Want to try it out but I don’t know how to consume csvkit as a module. Specifically, I want to use the CSVJSON utility. I need to pass it a csv file (and hopefully some other arguments,) but can’t quite figure out how to do this.
CSV JSON Docs

I want to pass the utility an uploaded csv file, the uploaded file could be in memory(if it is small enough) or in the temporary storage area. CSVJSON looks like it takes a file path or stream. It will be a nice bonus if someone can tell me what I need to do to the uploaded file for CSVJSON to be able to consume it.

In django 1.3 i’m planning to do the work in the form_valid method.

Hoping someone with some python skills can help show me what i need to do.
Thanks

  • 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-06-05T20:43:39+00:00Added an answer on June 5, 2026 at 8:43 pm

    You can import the CSVKit JSON class using the following code:

    from csvkit.utilities.csvjson import CSVJSON
    

    The CSVKit classes take 2 constructor options; the first is the command-line arguments list, the second is the output stream. If the output stream isn’t provided, it prints to the standard output.

    The argparser module is used to parse the command-line arguments, so it’s documentation will be helpful. The short version is that it’s just like splitting the raw string of arguments you’d use on the actual command-line by spaces. For example:

    $ csvjson --key Date /path/to/input/file
    

    would translate into:

    from csvkit.utilities.csvjson import CSVJSON
    args = ["--key", "Date", "/path/to/input/file"]
    CSVJSON(args).main()
    

    If you don’t want to read from an input file, but can’t pass the input file into stdin from the command-line, you can replace the sys.stdin object with your in-memory version. The only stipulation is that the object must behave like an input file. Presuming you have the string version of the CSV file in a variable called input_string, you can use the StringIO library to create a string buffer:

    import StringIO
    import sys
    new_stdin = StringIO.StringIO(input_string)
    sys.stdin = new_stdin
    args = ["--key", "Date"]
    CSVJSON(args).main()
    

    Lastly, if you want to print to a file instead of stdout, pass an open file object as the second parameter:

    output_file = open("/path/to/output.txt", "w")
    CSVJSON(args, output_file).main()
    output_file.close()
    

    Remember, it won’t flush the buffer until you close the file object yourself; CSVJSON won’t close it for you.

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

Sidebar

Related Questions

I need some help on processing a CSV file with gnuplot. My CSV file
I need to extract some data from a CSV file. The CSV is a
I need to delete some rows from csv file based on a column value.
I need to output some results as a .csv file, that gets parsed later
I need to export some data from SAS to CSV, so that I can
I need to export some numeric values from a given ASCII text file and
I am trying to create a csv file of some data. I have wrote
I need to export the results of a query to a csv file and
I really need some help on an issue: I'm converting an XML to CSV
I've got some csv-files that I need to import to our system using php.

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.