Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New import/export interface for 1.0 #46

Closed
kennethreitz opened this issue Jan 5, 2012 · 10 comments
Closed

New import/export interface for 1.0 #46

kennethreitz opened this issue Jan 5, 2012 · 10 comments

Comments

@kennethreitz
Copy link
Contributor

  • data.export('json') instead of data.json.
  • data.import('json', value) instead of data.json = value.
@felciano
Copy link

Why the change? I thought the current version was very elegant.

@ghost
Copy link

ghost commented May 23, 2012

This is a much needed change for two reasons: It's rather cumbersome to code an interface that lets you choose from a variety of different formats, because each module must currently be invoked as an object attribute. Also, this is needed to add support for import options, such as turning headers on and off.

@kennethreitz
Copy link
Contributor Author

@teilo 👍

@iurisilvio
Copy link
Collaborator

I like this interface to support several formats, but you just can't use import as a method name.

@iurisilvio
Copy link
Collaborator

I tried a first draft of this issue in branch import_export because I really need custom configuration to import/export.

I don't like the import_ name, but used it to avoid naming discussion.

It is backward compatible and should work with all registered formats.

>>> s = "a,b,c\nd,e,f\n"
>>> d1 = tablib.Dataset()
>>> d1.csv = s
>>> d2 = tablib.Dataset()
>>> d2.import_("csv", s)
>>> d1.export("json") == d2.json
True

This way, it is easy to configure importers and exporters.

>>> d = tablib.Dataset()
>>> d.import_("csv", "a;b;c\nd;e;f\n", delimiter=";")
>>> d.dict
[OrderedDict([(u'a', u'd'), (u'b', u'e'), (u'c', u'f')])]

iurisilvio added a commit that referenced this issue Feb 16, 2014
Make XLSX `freeze_panes` configuration optional to test the implementation.
@iurisilvio
Copy link
Collaborator

Any thoughts here?

I really think this is the way to go with tablib API. It easily integrates third-party formats and allow configurable inputs/outputs without creating new formats.

I'm already running my code in my reports and it fixed a lot of "can't use tablib here because of custom formats". CSV delimiters, large Excel files, import/export to custom formats (e.g. import data from SQLAlchemy and export to Google Charts).

@iurisilvio
Copy link
Collaborator

I'm thinking about this issue, maybe we can use the json module names.

dset.loads('csv', 'some,data')
dset.dumps('json')

After that, we can also support file descriptors with dset.load and dset.dump.

@pstch
Copy link

pstch commented May 1, 2014

Is there still work done on this at the moment ? I'd be glad to help, I realized I use tablib really often and that the project might need some help (seems like the main developer is quite busy atm).

I'm not really an experienced coder, but I have good understanding of Python, and I work with CSV/import/export libraries since a few months now so I may be able to do something.

@iurisilvio
Copy link
Collaborator

I don't know why I didn't saw it before, but tablib has import_set/import_book, which can be improved to accept a format parameter and work the way we want.

The dset.import_ is not necessary. All import_set format functions start with a dset.wipe(). If you want to load your data from an external source, you'll use anything from the dataset you created.

>>> tablib.import_set(text)  # auto detect format
>>> dset = tablib.import_set('{"my": "json"}', format='json')
>>> csv_text = dset.export(format='csv')

iurisilvio added a commit that referenced this issue Apr 5, 2015
Make XLSX `freeze_panes` configuration optional to test the implementation.
iurisilvio added a commit that referenced this issue Apr 5, 2015
…export` methods

and overloaded `import_set` and `import_book` functions.

Add import/export interface to Databook. Ref #46

Make XLSX `freeze_panes` configuration optional to test the implementation.

Extend `import_set` and `import_book` to support `format` and
`**kwargs` to be passed to the formatter.
@iurisilvio
Copy link
Collaborator

The #191 PR was merged and I think this is done. Also,

Maybe it deserve better docs.

dataset.export('xlsx', freeze_panes=False)
dataset.load('a,b,c\nv1,v2,v3\n', format='csv')

@Ev3 Ev3 closed this as completed Feb 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants