Skip to content


Subversion checkout URL

You can clone with
Download ZIP
An Activerecord-like library for doing basic CRUD operations with CSV files.
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.



What it is

It is a ruby library for dealing with csv file lines, with the same API you would deal with Activerecord objects using a datadase. You can instantiate objects and manipulate, add validations and persist them just like you would do with Activerecord objects (still with some limitations).

What it is not

It is not an ORM. There are no relations between models (at the level of the data), since there are just csv files. There is no tables, so forget relational model.

When not use it

It's not a good idea keep object-related data in CSV files and build systems relying on it. If you don't want to use database, but rather store data in a file, try Sqlite.

When use it

When dealing with integration with legacy systems, you might need manipulate csv data along with database's data objects. You will use very similar API, but don't forget, csv data (sor far) cannot have relations.


Just run:

	gem install active_csv

How to setup a model to use AtivceCSV

  • Include the ative_csv in the Gemfile

#Gemfile gem 'active_csv','0.1.2'

  • Run bundle install

$ bundle install

  • Change the class the model so it inherits from ActiveCSV instead of ActiveRecord, like the following

#app/models/client.rb class Client < ActiveCSV end

  • Include attr_accessor with all the attributes in the model file

#app/models/client.rb attr_accessor :name, :address

  • Create the csv_attributes.yml (or equivalent) file in the config folder, and include on it the model and the attributes

#config/csv_attriubutes.yml client: name, address

  • If you want, you can name the yml and CSV files, overwrinting the defaults, so it would look like

#app/models/client.rb class Client < ActiveCSV attr_accessor :name, :address set_attr_file_name “config/something.yml” # default is 'config/csv_attributes.yml' set_csv_file_name “db/other_something.csv” # default is the lowercase version of the model name. In this case, 'db/client.csv'. end

  • You can include some validation in the model if you want

#app/models/client.rb validates_presence_of :name


So far the API is limited to a few methods. Here's some examples:

client =>“Tim”)

client_one = Client.find(3) client_one.update_attributes(:name=>“Tommas Edson”) client_one.persisted?

client_two = Model.find({:attr=>“value”, :another_attr=>“value”}) # This is not AR-like, and will be changed in the future to meet AR's API client_two.destroy

@clients = Client.all

Found a bug?

Please let me know via email or create an issue on github.




ActiveCSV is released under the MIT license.

Something went wrong with that request. Please try again.