Skip to main content

PyPI - License PyPI - Python Version PyPI Build Status

Overview

faro is a fast, simple, and intuitive SQL-driven data analysis library for Python. It is built on top of sqlite and is intended to complement the existing data analysis packages in the Python eco-system, such as numpy, pandas, and matplotlib by providing easy interoperability between them. It also integrates with Jupyter by default to provide readable and interactive displays of queries and tables.

Usage

Create a Database object and give it a name.

from faro import Database

db = Database('transportation')

To add tables to the in-memory database, simply specify the name of the file. Supported file types include: csv, json, and xlsx. add_table inserts the contents of a file into a new table within the database. It can automatically detect the filetype and parse the file contents accordingly. In this example we load two different tables, one in csv format, and the other in json format.

db.add_table('cars.json', name='cars')
db.add_table('airports.csv', name='airports')

We can also directly pass pandas.DataFrame or faro.Table objects to be added to the database. A helpful pattern when dealing with more complex parsing for a specific file is to read it into memory using pandas then add the DataFrame to the faro.Database.

buses = pd.DataFrame({
  'id' : [1, 2, 3, 4, 5],
  'from' : ['Houston', 'Atlanta', 'Chicago', 'Boston', 'New York'],
  'to' : ['San Antonio', 'Charlotte', 'Milwaukee', 'Cape Cod', 'Buffalo']
})

db.add_table(buses, name='buses')

Alternatively, we can directly assign to a table name as a property of the table object. Using this method, however, will also replace the entire table as opposed to the options offered by add_table()

db.table.buses = buses

We can now query against any table in the database using pure SQL, and easily interact with the results in a Jupyter Notebook.

sql = """
SELECT iata,
       name,
       city,
       state
  FROM airports
 WHERE country = 'USA'
 LIMIT 5
"""
db.query(sql)
iata name city state
0 00M Thigpen Bay Springs MS
1 00R Livingston Municipal Livingston TX
2 00V Meadow Lake Colorado Springs CO
3 01G Perry-Warsaw Perry NY
4 01J Hilliard Airpark Hilliard FL

If we want to interact with the data returned by the query, we can easily transform it into whatever data type is most convenient for the situation. Supported type conversions include: List[Tuple], Dict[List], numpy.ndarray, and pandas.DataFrame.

table = db.query(sql)
type(table)
>>> faro.table.Table

df = table.to_dataframe()
type(df)
>>> pandas.core.frame.DataFrame

matrix = table.to_numpy()
type(matrix)
>>> numpy.ndarray

We can also interact with the tables in our database by accessing them as properties of the table object. For example:

db.table.buses
id from to
1 1 Houston San Antonio
2 2 Atlanta Charlotte
3 3 Chicago Milwaukee
4 4 Boston Cape Cod
5 5 New York Buffalo

Metadata

Release files for faro 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for faro 0.0.4
File Size Uploaded Provenance Actions
faro-0.0.4.tar.gz 8.3 kB Without provenance Details for faro-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for faro 0.0.4
File Interpreter ABI Platform Actions
faro-0.0.4-py3-none-any.whl Python 3 none any Details for faro-0.0.4-py3-none-any.whl

Total release size: 16.0 kB

Release files / faro-0.0.4.tar.gz

Download URL faro-0.0.4.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d2ec27ce13d705534343c33f2a6252ad68ac18a0749eb38dd6954701ac1d0f0e
BLAKE2b-256 checksum
How to use checksums
8fc2897e1fc4df37e3a45eadcf7522eb4daebd9cd00372430710fa65a73eac90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.7.3 Darwin/19.4.0

Release files / faro-0.0.4-py3-none-any.whl

Download URL faro-0.0.4-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fbe8796d208dea613d6efd14682d6922a285309a513ec2e38eac175d93fcfd33
BLAKE2b-256 checksum
How to use checksums
4348290dcf54bedd55089cadc0457c4a001c5be9df96980feca7c21d36296d55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.7.3 Darwin/19.4.0

Security for faro 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page