{"id":18332825,"url":"https://github.com/creatiwity/siren","last_synced_at":"2026-05-24T16:01:06.246Z","repository":{"id":37884856,"uuid":"214398463","full_name":"Creatiwity/siren","owner":"Creatiwity","description":"Siren API to serve INSEE v3 data","archived":false,"fork":false,"pushed_at":"2025-03-04T14:54:34.000Z","size":925,"stargazers_count":17,"open_issues_count":2,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-21T16:21:26.878Z","etag":null,"topics":["api","docker-image","insee","rust","siren","siren-api","sirene"],"latest_commit_sha":null,"homepage":"https://creatiwity.net/realisations/api-siren/23","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Creatiwity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-11T09:36:54.000Z","updated_at":"2025-02-21T13:28:01.000Z","dependencies_parsed_at":"2023-02-17T20:31:06.849Z","dependency_job_id":"3a2df376-8235-4297-92dd-63c24598d6ea","html_url":"https://github.com/Creatiwity/siren","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Creatiwity%2Fsiren","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Creatiwity%2Fsiren/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Creatiwity%2Fsiren/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Creatiwity%2Fsiren/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Creatiwity","download_url":"https://codeload.github.com/Creatiwity/siren/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430838,"owners_count":20937873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","docker-image","insee","rust","siren","siren-api","sirene"],"created_at":"2024-11-05T19:40:14.078Z","updated_at":"2026-05-24T16:01:06.238Z","avatar_url":"https://github.com/Creatiwity.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SIREN API\n\n[![Build Status](https://github.com/Creatiwity/siren/workflows/Build/badge.svg?branch=develop)](https://github.com/Creatiwity/siren/actions?query=workflow%3ABuild)\n[![docker pulls](https://img.shields.io/docker/pulls/creatiwity/siren.svg)](https://hub.docker.com/r/creatiwity/siren/)\n[![docker image info](https://images.microbadger.com/badges/image/creatiwity/siren.svg)](http://microbadger.com/images/creatiwity/siren)\n[![docker tag](https://images.microbadger.com/badges/version/creatiwity/siren.svg)](https://hub.docker.com/r/creatiwity/siren/tags/)\n\nREST API for serving INSEE files v3 with full-text search and geographic search capabilities.\n\n## Getting started\n\nTo have a working copy of this project, follow the instructions.\n\n### Installation\n\n1. **Setup Rust**: Install [Rust](https://www.rust-lang.org) (version 1.70+ recommended)\n\n2. **Environment variables**: Define your environment variables as defined in `.env.sample`. You can either manually define these environment variables or use a `.env` file.\n\n3. **PostgreSQL database**: Setup PostgreSQL with required extensions (macOS commands):\n\n```bash\nbrew install postgresql\ncreateuser --pwprompt sirene # set password to sirenepw for instance\ncreatedb --owner=sirene sirene\n\n# Connect to database and enable required extensions\npsql -U sirene -d sirene\nCREATE EXTENSION IF NOT EXISTS postgis;\nCREATE EXTENSION IF NOT EXISTS pg_trgm;\nCREATE EXTENSION IF NOT EXISTS unaccent;\n\\q\n```\n\n4. **Required PostgreSQL extensions**:\n   - `postgis` (for geographic search)\n   - `pg_trgm` (for full-text search with trigram similarity)\n   - `unaccent` (for accent-insensitive search, via immutable wrapper)\n\n5. **Optional**: For development, you may want to install:\n```bash\nbrew install diesel_cli  # For database migrations\ncargo install cargo-watch  # For auto-reloading during development\n```\n\n## Documentation\n\n### Configuration\n\nRecommended configuration for production with docker:\n\n```\nRUST_LOG=sirene=warn\nSIRENE_ENV=production\nBASE_URL=[Your base URL, needed to update asynchronously]\nAPI_KEY=[Any randomized string, needed to use the HTTP admin endpoint]\nDATABASE_URL=postgresql://[USER]:[PASSWORD]@[PG_HOST]:[PG_PORT]/[PG_DATABASE]\nDATABASE_POOL_SIZE=100\nINSEE_CREDENTIALS=[API_KEY]\n```\n\n**How to generate INSEE_CREDENTIALS**\n\nThis variable is only needed if you want to have the daily updates.\n\n1. Go to https://portail-api.insee.fr/catalog/all\n2. Create an account or sign in\n3. Create an application on this portal\n4. Subscribe this application to API SIRENE (Sirene 4 - v3.11)\n5. Generate a key in the application details\n6. Copy the key paste it in `.env` instead of `[API_KEY]`\n\n### CLI\n\n**\u003e sirene --help**\n\n```\nSirene service used to update data in database and serve it through a HTTP REST API\n\nUsage: sirene \u003cCOMMAND\u003e\n\nCommands:\n  update  Update data from CSV source files\n  serve   Serve data from database to /unites_legales/\u003csiren\u003e and /etablissements/\u003csiret\u003e\n  help    Print this message or the help of the given subcommand(s)\n\nOptions:\n  -h, --help     Print help\n  -V, --version  Print version\n```\n\n**\u003e sirene serve --help**\n\n```\nServe data from database to /unites_legales/\u003csiren\u003e and /etablissements/\u003csiret\u003e\n\nUsage: sirene serve [OPTIONS] --env \u003cENVIRONMENT\u003e --port \u003cPORT\u003e --host \u003cHOST\u003e\n\nOptions:\n      --env \u003cENVIRONMENT\u003e    Configure log level [env: SIRENE_ENV=development] [possible values: development, staging, production]\n      --port \u003cPORT\u003e          Listen this port [env: PORT=3000]\n      --host \u003cHOST\u003e          Listen this host [env: HOST=localhost]\n      --api-key \u003cAPI_KEY\u003e    API key needed to allow maintenance operation from HTTP [env: API_KEY=]\n      --base-url \u003cBASE_URL\u003e  Base URL needed to configure asynchronous polling for updates [env: BASE_URL=http://localhost:3000]\n  -h, --help                 Print help\n```\n\n**\u003e sirene update --help**\n\n```\nUpdate data from CSV source files\n\nUsage: sirene update [OPTIONS] \u003cGROUP_TYPE\u003e [COMMAND]\n\nCommands:\n  update-data   Download, unzip and load CSV file in database in loader-table\n  swap-data     Swap loader-table to production\n  sync-insee    Synchronise daily data from INSEE since the last modification\n  finish-error  Set a staled update process to error, use only if the process is really stopped\n  help          Print this message or the help of the given subcommand(s)\n\nArguments:\n  \u003cGROUP_TYPE\u003e  Configure which part will be updated [possible values: unites-legales, etablissements, all]\n\nOptions:\n      --force  Force update even if the source data where not updated\n  -h, --help   Print help\n```\n\n### HTTP API\n\n#### Lookup Endpoints\n\n```\nGET /v3/unites_legales/\u003csiren\u003e\nGET /v3/etablissements/\u003csiret\u003e\n```\n\n#### Search Endpoints (NEW!)\n\n**Search Establishments**\n```\nGET /v3/etablissements?q=\u003ctext\u003e\u0026lat=\u003clatitude\u003e\u0026lng=\u003clongitude\u003e\u0026radius=\u003cmeters\u003e\u0026sort=\u003cfield\u003e\u0026direction=\u003casc|desc\u003e\u0026limit=\u003cnumber\u003e\u0026offset=\u003cnumber\u003e\n```\n\n**Search Legal Units**\n```\nGET /v3/unites_legales?q=\u003ctext\u003e\u0026sort=\u003cfield\u003e\u0026direction=\u003casc|desc\u003e\u0026limit=\u003cnumber\u003e\u0026offset=\u003cnumber\u003e\n```\n\n**Query Parameters**:\n\n- `q`: Full-text search query (searches in denomination and commune name for establishments, denomination only for legal units)\n- `lat`, `lng`, `radius`: Geographic search (establishments only) - filters results within radius meters from (lat,lng) point\n- `sort`: Sort field - `distance` (geo only), `relevance` (text search), `date_creation`, `date_debut`\n- `direction`: Sort direction - `asc` or `desc` (defaults to sensible values per sort field)\n- `limit`: Results per page (default: 20, max: 100)\n- `offset`: Pagination offset (default: 0, max: 10000)\n\n\u003e **`total` field**: exact count for filter-only queries; capped at 10,000 for text searches (`q`) — if `total == 10000` there may be more results.\n- `etat_administratif`: Filter by administrative status (A=active, F=closed)\n- `code_postal`: Filter by postal code\n- `siren`: Filter by SIREN (establishments only)\n- `code_commune`: Filter by commune code\n- `activite_principale`: Filter by main activity code\n- `etablissement_siege`: Filter by headquarters status (establishments only)\n- `categorie_juridique`: Filter by legal category (legal units only)\n- `categorie_entreprise`: Filter by company category (legal units only)\n- `date_creation`: Filter by creation date (legal units only)\n- `date_debut`: Filter by start date (legal units only)\n\n**Maintenance**\n\n_This API is enabled only if you have provided an API_KEY when starting the `serve` process._\n\n```\nPOST /admin/update\n\n{\n    api_key: string,\n    group_type: \"UnitesLegales\" | \"Etablissements\" | \"All\",\n    force: bool,\n    asynchronous: bool,\n}\n```\n\nIf `asynchronous` is set to `true`, the update endpoint will immediately return the following:\n\n```\nStatus: 202 Accepted\nLocation: /admin/update/status?api_key=string\nRetry-After: 10\n\n[Initial status for the started update]\n```\n\n```\nGET /admin/update/status?api_key=string\n```\n\nIf an update is in progress, the status code will be 202, otherwise 200.\n\n```\nPOST /admin/update/status/error\n\n{\n    api_key: string,\n}\n```\n\n### Basic usage\n\nServe:\n\n```\ncargo run serve\n```\n\nUpdate:\n\n```\ncargo run update all\n```\n\nHelp:\n\n```\ncargo run help\n```\n\n## Features\n\n### Core Features\n- REST API for INSEE SIREN/SIRET data\n- Automatic updates from INSEE API\n- PostgreSQL backend with efficient indexing\n- Docker support for easy deployment\n\n### New Search Features (v5.0+)\n- **Full-text search**: Trigram similarity (`pg_trgm`) with case and accent-insensitive matching for partial and fuzzy matches\n- **Geographic search**: Radius filtering and distance-based sorting using PostGIS\n- **Field filtering**: Filter by administrative status, activity codes, dates, etc.\n- **Flexible sorting**: By relevance, distance, or dates\n- **Pagination**: Efficient offset/limit pagination — exact total for filter-only queries, capped at 10,000 for text searches (`q`) to avoid full-table counts\n\n### Technical Features\n- **PostgreSQL extensions**: PostGIS for spatial data, pg_trgm + unaccent for full-text search\n- **Optimized queries**: Raw SQL with parameterized queries for performance\n- **OpenAPI documentation**: Complete API documentation via Scalar\n- **Async support**: Optional asynchronous updates for large datasets\n\n## Tests\n\n```bash\ncargo test\n```\n\n## Deployment\n\nA docker image is built and a sample `docker-compose.yml` with its `docker` folder are usable to test it.\n\n### Docker Setup\n\n```bash\ndocker-compose up -d\n```\n\n### Environment Variables\n\nRequired for production:\n```\nRUST_LOG=sirene=warn\nSIRENE_ENV=production\nBASE_URL=https://your-domain.com\nAPI_KEY=your-secret-key\nDATABASE_URL=postgresql://user:password@db:5432/sirene\nDATABASE_POOL_SIZE=100\nINSEE_CREDENTIALS=your-insee-api-key\n```\n\n## Migration depuis pg_search\n\nSi vous avez une installation existante qui utilise l'extension `pg_search` (ParadeDB), exécutez le script de migration manuelle fourni à la racine du projet :\n\n```bash\npsql -U sirene -d sirene -f migrate_from_pg_search.sql\n```\n\nCe script (transactionnel) :\n1. Supprime les anciens index BM25 ParadeDB\n2. Active `pg_trgm` et `unaccent`\n3. Crée la fonction `immutable_unaccent()` (wrapper IMMUTABLE requis pour les index)\n4. Reconstruit `search_denomination` avec normalisation `lower(immutable_unaccent(...))`\n5. Crée les nouveaux index GIN\n6. Recrée les tables de staging pour hériter des nouveaux index et colonnes\n7. Désactive l'extension `pg_search`\n\nLes nouvelles installations n'ont pas besoin de ce script : les migrations Diesel utilisent directement `pg_trgm`.\n\n## Development\n\n### Running locally\n\n```bash\n# Start the server\ncargo run -- serve --env development --port 8080 --host 0.0.0.0\n\n# Run tests\ncargo test\n\n# Run with auto-reload\ncargo watch -x 'run -- serve --env development --port 8080'\n```\n\n### Database Migrations\n\n```bash\n# Run migrations\ndiesel migration run\n\n# Create new migration\ndiesel migration generate migration_name\n```\n\n## API Documentation\n\nThe API includes comprehensive OpenAPI documentation accessible at:\n- `/scalar` - Interactive Scalar API documentation\n- `/openapi.json` - OpenAPI specification\n\n## Examples\n\n### Search Establishments\n\n```bash\n# Text search\ncurl \"http://localhost:8080/v3/etablissements?q=boulangerie\u0026limit=5\"\n\n# Geographic search (within 1km of Eiffel Tower)\ncurl \"http://localhost:8080/v3/etablissements?lat=48.8584\u0026lng=2.2945\u0026radius=1000\u0026sort=distance\"\n\n# Combined search with filters\ncurl \"http://localhost:8080/v3/etablissements?q=restaurant\u0026code_postal=75001\u0026etat_administratif=A\u0026sort=relevance\u0026limit=10\"\n```\n\n### Search Legal Units\n\n```bash\n# Text search with sorting\ncurl \"http://localhost:8080/v3/unites_legales?q=creati\u0026sort=date_creation\u0026direction=desc\u0026limit=5\"\n\n# Filter by activity code\ncurl \"http://localhost:8080/v3/unites_legales?activite_principale=62.01Z\u0026categorie_juridique=5710\"\n```\n\n## Authors\n\n- **Julien Blatecky** - [@Julien1619](https://twitter.com/Julien1619)\n\n## License\n\n[MIT](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreatiwity%2Fsiren","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreatiwity%2Fsiren","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreatiwity%2Fsiren/lists"}