A lightweight, zero-dependency Python library for reading, writing, querying, and joining CSV files.
Project description
easycsv
A lightweight, zero-dependency Python library for reading, writing, querying, and joining CSV files — with a syntax far simpler than pandas.
pip install easycsv-py
Quick Start
from easycsv import CSV
data = CSV.load("people.csv")
# Bracket syntax
print(data["name"].values()) # all names
print(data[0]) # first row
print(data[0:3]) # first 3 rows as new CSV
# SQL-style query (auto-converts "25" -> 25)
adults = data.query("age > 18 and city == 'Boston'")
print(adults.values("name"))
# Membership check
if not data.contains_in("email", "alice@example.com"):
data.add_row({"name": "Alice", "email": "alice@example.com", "age": "22"})
data.save()
Features
File Operations
data = CSV.load("path/to/file.csv")
data = CSV.create("path/to/new.csv", headers=["name", "age", "city"])
data.save()
data.save("backup/file.csv") # saves to a new path, creates folders
Row Operations
data.get_row(0)
data.add_row({"name": "Bob", "age": "30"})
data.insert_row(2, {"name": "Alice", "age": "22"})
data.edit_row(0, {"name": "Bob", "age": "35"})
data.delete_row(0)
data.get_row_index({"name": "Bob", "age": "35"})
Column Operations
data.get_column("age") # plain list
data.column("age") # ColumnSet with analytics
data.add_column("country", "USA")
data.delete_column("city")
data.drop_columns("city", "zip")
data.rename_column("age", "Age")
data.edit_column("age", lambda x: str(int(x) + 1))
Cell Operations
data.get_cell(0, "name")
data.edit_cell(0, "name", "Alice")
Bracket Syntax
data["age"] # ColumnSet
data[0] # row dict
data[0:5] # new CSV object (slice)
data["status"] = "Active" # set whole column
data["score"] = [90, 85, 99] # set column from list
data[0] = {"name": "Bob", ...} # replace row
Searching
data.find_rows("city", "Boston") # RowSet
data.find_rows_by_value("Boston") # RowSet (searches everywhere)
data.find_row_indexes("city", "Boston") # plain list of indexes
data.find_column("age") # plain list of values
data.find_columns("na") # headers containing "na"
data.find_columns_by_value("Boston") # headers whose column contains value
data.find_cells("John") # [(row_index, col_name), ...]
data.search("city", "Boston") # alias for find_rows
Membership Checking
data.contains("John") # anywhere in CSV
data.contains_in("email", "a@example.com") # in specific column
data.row_exists(name="Alice", age="22") # exact row match
data.column_exists("email") # header check
Filtering & Updating
data.where(city="Boston") # RowSet
data.filter(city="Boston", age="22") # alias for where
data.update("city", "Boston", status="VIP") # update matching rows
data.delete_where(status="Banned") # delete matching rows
SQL-Style Query
# Strings auto-convert to numbers for math comparisons
results = data.query("age > 20 and city == 'Boston'")
results = data.query("score >= 90 or status == 'VIP'")
CSV Joins
users = CSV.load("users.csv")
orders = CSV.load("orders.csv")
users.join(orders, on="user_id", how="left") # left join
users.join(orders, on="user_id", how="inner") # inner join
Analytics
data.sum("price")
data.avg("age")
data.min("score")
data.max("score")
data.unique("city")
data.count("city") # {"Boston": 3, "NY": 5}
RowSet (returned by searches/queries)
rows = data.find_rows("city", "Boston")
rows.values("name") # ['Alice', 'Bob']
rows.first() # first matched row dict
rows.last() # last matched row dict
rows.indexes() # [2, 5, 7]
rows.count() # 3
rows.update(status="VIP")
rows.delete()
for row in rows: # iterable
print(row)
ColumnSet (returned by column access)
col = data["age"]
col.values() # ['25', '30', '22']
col.sum()
col.avg()
col.min()
col.max()
col.unique()
col.count() # {"25": 1, "30": 2}
col.contains("25")
Utilities
data.sort("age")
data.sort("age", reverse=True)
data.remove_duplicates()
data.remove_duplicates(column="email")
data.reverse()
data.shuffle()
data.select("name", "age") # returns new CSV with only those columns
data.copy() # deep copy
data.head(5) # print first 5 rows
data.tail(5) # print last 5 rows
data.show() # print full table
data.to_list() # list of dicts
data.to_dict("name") # dict keyed by column
data.to_json() # JSON string
data.from_list([{"name": "Alice", "age": "22"}])
len(data) # row count
repr(data) # CSV('file.csv', 3 rows, 4 columns)
Why easycsv?
| Feature | easycsv | pandas |
|---|---|---|
| Dependencies | 0 | numpy, etc. |
| Install size | ~10 KB | ~30 MB |
| Learning curve | Easy | Steep |
| CSV joins | Yes | Yes |
| SQL-style queries | Yes | Yes |
| Best for | Scripts, APIs, bots | Big data, ML |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
easycsv_py-5.0.1.tar.gz
(13.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easycsv_py-5.0.1.tar.gz.
File metadata
- Download URL: easycsv_py-5.0.1.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fd693f9fbd04da320b796ffa74920d7c8fe92fcd2e76b7da2881a2fe5d9e818
|
|
| MD5 |
2c59c73a89b1b3cbeb6ff64dde16034d
|
|
| BLAKE2b-256 |
9dc63f8ee5cab087190fa28589f05d079615d23cb21cc14a33a808a97935574a
|
File details
Details for the file easycsv_py-5.0.1-py3-none-any.whl.
File metadata
- Download URL: easycsv_py-5.0.1-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c5ac1a347114002216fe55211b804a4f3414eb092e85069b817315c97dad20c
|
|
| MD5 |
b229118d530f8b0bcacaf51d11b8decb
|
|
| BLAKE2b-256 |
6a50a00b99d1426f20f7d49004be7dbb3a38e3203d0d511fdc59d6b93432d1f0
|