How to programmatically create a large taxonomy in Drupal 7?
Myself still learning how to properly write modules, I managed to come up with the following code for saving the terms into separate table named MODULENAME_data. It may not be perfect - but it apparently worked. I'm open to downvoting, but even more to suggestions on how to improve it.

// Make the table name a constant for easier coding
// We will store it's vid as system variable after we have created it
define("MODULENAME_VOCAB_MACHINE_NAME", "iso_639_3_codes_data");

function MODULENAME_enable(){
  // Create the vocabulary.
  $vocab = array(
    'name' =&gt; 'Vocabulary name',
    'machine_name' =&gt; MODULENAME_VOCAB_MACHINE_NAME,
    'description' =&gt; t('Vocabulary of iso 639-3 language codes'),
    'module' =&gt; 'taxonomy',
    'hierarchy' =&gt; 0,
    'module' =&gt; 'MODULENAME',
  );
  taxonomy_vocabulary_save( (object) $vocab);

  // Now that we've created the vocabulary, let's store its vid as a system variable
  $vocab = taxonomy_vocabulary_machine_name_load(MODULENAME_VOCAB_MACHINE_NAME);
  $vid = $vocab-&gt;vid;
  variable_set('MODULENAME_vocab_id', $vid);

  // Create custom field.
  $field = array(
    'field_name' =&gt; 'field_custom_field',
    'type' =&gt; 'text',
    'label' =&gt; t('Symbol') // where is that used? I dunno, but API says so ;-)
  );
  field_create_field($field);

  // Create field instance on the vocab
  $instance = array(
    'field_name' =&gt; 'field_custom_field',
    'entity_type' =&gt; 'taxonomy_term',
    'bundle' =&gt; MODULENAME_VOCAB_MACHINE_NAME,
    'label' =&gt; t('Custom field'),
    'description' =&gt; t('Description'),
    'required' =&gt; true,
    'widget' =&gt; array(
      'type' =&gt; 'text_textfield',
     )
  );
  field_create_instance($instance);

  // Here you would include an include file that provides row data
  // (probably an array) and then iterate over it to populate table
  // such as

      // Save terms.
      foreach ($items as $item) {
        taxonomy_term_save((object) array(
          'name' =&gt; $item[0],
          'vid' =&gt; $vid, 
          'field_custom_field' =&gt; array(
            LANGUAGE_NONE =&gt; array(
              0 =&gt; array(
                'value' =&gt; $item[1] ,
              )
            )
          ),    
        ));

}

function MODULENAME_disable(){
  // Some system cleanup.

  // Delete vocabulary. This deletes terms and field references too.
  taxonomy_vocabulary_delete(variable_get('MODULENAME_vocab_id'));

  // Delete variable from system.
  variable_del('MODULENAME_vocab_id');
}


Word of comment:


I'm still not sure whether the hook_disable() would be supposed to do what I put into it, but my understanding is that once a module is disabled, the features installed by it would be supposed to be unavailable too. I'm unsure about the field references - not only do they remain in the system in my code, but once we re-enable the module, the references will not be restored due to new IDs.
I'm also not sure how one would make the vocabulary i18n-savvy, meaning - when you would like to install the vocabulary along with translations - vocabularies provide several i18n modes and I'm not in the knowledge how to support them programatically.


This is something I would love to learn from someone.