Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
s-raza+S20-Win authored and s-raza+S20-Win committed Oct 3, 2021
2 parents 283061b + eab3a71 commit ab44d53
Show file tree
Hide file tree
Showing 24 changed files with 1,168 additions and 256 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ instance/
.scrapy

# Sphinx documentation
docs/_build/
docs/build/
docs/source/_build

# PyBuilder
target/
Expand Down
13 changes: 13 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**2021-10-03**

*Version 0.2.0*

- Construct a nested dictionary from rows based on a list of ordered column names `... read more <https://csvio.readthedocs.io/en/latest/csvio.csvbase.html#csvio.csvbase.CSVBase.rows_to_nested_dicts>`_
- Update/Fix documentation
- Refactor/Add tests

**2021-09-24**

*Version 0.1.0*

- First release
109 changes: 0 additions & 109 deletions README.md

This file was deleted.

127 changes: 127 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
.. image:: https://github.com/s-raza/csvio/blob/master/docs/source/_static/csvio_logo_240x160px.png?raw=True
:align: center
:target: https://github.com/s-raza/csvio
:alt: csvio Logo

csvio: Python Library for processing CSV files
==============================================

.. image:: https://img.shields.io/github/license/s-raza/csvio?color=bright
:alt: GitHub License
:target: https://github.com/s-raza/csvio/blob/master/LICENSE

.. image:: https://img.shields.io/badge/python-3.8%2B-bright
:alt: Python Versions

.. image:: https://img.shields.io/readthedocs/csvio/latest
:alt: Readthedocs
:target: https://csvio.readthedocs.io/en/latest

csvio is a Python library that provides a wrapper around Python's built in
:obj:`csv.DictReader` and :obj:`csv.DictWriter`, for ease of reading and
writing CSV files.

Rows in a CSV are represented and processed as a list of dictionaries. Each
item in this list is a dictionary that represents a row. The key, value pairs
in each dictionary is a mapping between the column and its associated row value
from the CSV.

Installation
------------

.. code-block:: bash
pip install csvio
Documentation
-------------

`Readthedocs <https://csvio.readthedocs.io>`_

Reading CSVs
------------

.. code-block:: python
>>> from csvio import CSVReader
>>> reader = CSVReader("fruit_stock.csv")
>>> reader.fieldnames
['Supplier', 'Fruit', 'Quantity']
>>> len(reader.rows)
4
>>> import json
>>> print(json.dumps(reader.rows, indent=4))
[
{
"Supplier": "Big Apple",
"Fruit": "Apple",
"Quantity": "1"
},
{
"Supplier": "Big Melons",
"Fruit": "Melons",
"Quantity": "2"
},
{
"Supplier": "Long Mangoes",
"Fruit": "Mango",
"Quantity": "3"
},
{
"Supplier": "Small Strawberries",
"Fruit": "Strawberry",
"Quantity": "4"
}
]
CSV file contents:

.. code-block:: bash
Supplier,Fruit,Quantity
Big Apple,Apple,1
Big Melons,Melons,2
Long Mangoes,Mango,3
Small Strawberries,Strawberry,4
Writing CSVs
------------

.. code-block:: python
>>> from csvio import CSVWriter
>>> writer = CSVWriter("fruit_stock.csv", fieldnames=["Supplier", "Fruit", "Quantity"])
>>> row1 = {"Supplier": "Big Apple", "Fruit": "Apple", "Quantity": 1}
>>> writer.add_rows(row1)
>>> rows2_3_4 = [
... {"Supplier": "Big Melons", "Fruit": "Melons", "Quantity": 2},
... {"Supplier": "Long Mangoes", "Fruit": "Mango", "Quantity": 3},
... {"Supplier": "Small Strawberries", "Fruit": "Strawberry", "Quantity": 4}
... ]
>>> writer.add_rows(rows2_3_4)
>>> len(writer.pending_rows)
4
>>> len(writer.rows)
0
>>> writer.flush()
>>> len(writer.pending_rows)
0
>>> len(writer.rows)
4
Once flush is called a CSV file with the name *fruit_stock.csv* will be
written with the following contents.

.. code-block:: bash
Supplier,Fruit,Quantity
Big Apple,Apple,1
Big Melons,Melons,2
Long Mangoes,Mango,3
Small Strawberries,Strawberry,4
.. ignore-below-marker
25 changes: 24 additions & 1 deletion csvio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
__version__ = "0.1.0"
# MIT License
#
# csvio: A library for conveniently processing CSV files.
#
# Copyright (c) 2021 Salman Raza <raza.salman@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
__version__ = "0.2.0"
from .csvreader import CSVReader
from .csvwriter import CSVWriter

0 comments on commit ab44d53

Please sign in to comment.